今天在编译程序时碰到该问题:
whetstone.c:(.text+0x56c): undefined reference to `sin'
whetstone.c:(.text+0x585): undefined reference to `cos'
whetstone.c:(.text+0x5cf): undefined reference to `atan'
检查头文件math.h已经包含,原来虽然程序中已经包含math.h,但在链接时要链接到数学库,加上-lm编译选项即可,如下:
将gcc whetstone.c -o whetstone改为 gcc whetstone.c -lm -o whetstone即可。