天天看點

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

繼續閱讀