【发布时间】:2012-04-07 23:16:17
【问题描述】:
我有一个调用 sin、cos 和 acos 的 c 程序。编译时出现以下错误:
/tmp/ccDfW98S.o: In function `zip_search':
main.c:(.text+0xf30): undefined reference to `sin'
main.c:(.text+0xf45): undefined reference to `sin'
main.c:(.text+0xf66): undefined reference to `cos'
main.c:(.text+0xf7b): undefined reference to `cos'
main.c:(.text+0xf9c): undefined reference to `cos'
main.c:(.text+0xfc6): undefined reference to `acos'
collect2: ld returned 1 exit status
我知道这在您不使用 -lm gcc 标志时很常见。我正在使用这个标志。我这样称呼 GCC:
gcc -o zipcode-server -lm main.c
当我在我的一台计算机上编译时,它工作正常。我能想到的唯一区别是它不能在 x86_64 上运行,而它运行的计算机是 i686。两者都是Ubuntu。文件 libm.a 存在于它不工作的计算机上,我没有收到任何错误说找不到它。这可能是什么原因造成的?
【问题讨论】:
-
能否请您发布代码的相关部分,以便我们帮助您解决问题?
-
只是为了好玩试试:
gcc -o zipcode-server main.c -lm