Eclipse 3.8.1 Linux Mint
将 -lm 添加到项目/C/C++ 构建/设置/GCC C 链接器/命令:
gcc -lm
控制台消息:
Building target: Nicomedes
Invoking: GCC C Linker
gcc -lm -o "Nicomedes" ./Nicomedes.o
./Nicomedes.o: In function `main':
/home/bogwan/work/Nicomedes/Debug/../Nicomedes.c:244: undefined reference to `pow'
/home/bogwan/work/Nicomedes/Debug/../Nicomedes.c:258: undefined reference to `atan'
/home/bogwan/work/Nicomedes/Debug/../Nicomedes.c:260: undefined reference to `atan'
collect2: error: ld returned 1 exit status
make: *** [Nicomedes] Error 1
07:29:58 Build Finished (took 108ms)
最佳答案
您的链接顺序错误。使其成为 gcc -o "Nicomedes"./Nicomedes.o -lm。 在链接顺序中,需要符号定义的文件必须位于之前 提供定义的那些。所以库在目标文件之后。
在 Eclipse 中,设置C/C++ Build -> 设置 -> GCC C Linker -> 命令 旨在设置您想要进行链接的程序,而不是您的链接 选项。在C/C++ Build中设置库选项 -> 设置 -> GCC C Linker -> 库
关于linux - gcc -lm 无法修复对 `atan' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36824542/