linux - gcc -lm 无法修复对 `atan' 的 undefined reference

标签 linux math gcc linker

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/

相关文章:

矩阵内的 C++ 正弦函数

javascript - 使用回调创建函数

c - strptime() 在 armv7l 环境中产生错误结果

c - 无法找到-lGL,没有符号链接(symbolic link)怎么办?

java - 求 200 万以下所有素数的和

c++ - NetBeans IDE gcc 编译器优化选项

linux - apt-get 升级失败,主机名错误

linux - 将今天的日期与 future 的日期进行比较会导致一元运算符错误

linux - 内核中的 sock_create()

linux - 磁盘 IO 期间 sssd_nss 的高 CPU 使用率