天天看点

Linux(ubuntu) undefined reference to `sin'问题解决

今天在编译程序时碰到该问题:

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即可。

继续阅读