不熟悉的错误

时间:2012-11-08 17:37:46

标签: c multithreading unix ceil

我正在编写一个处理线程的程序,我几乎完全可以使用它。不幸的是,我遇到了一个我不熟悉的语法错误(重复4次)。这是我的编译命令的快速剪辑,以及随后的错误:

 gcc -o threads threads.cpp -pthread<br>
/tmp/ccy8maS0.o: In function `tenPercentA()':
threads.cpp:(.text+0xde): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `tenPercentB()':
threads.cpp:(.text+0x1c6): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `fiftPercentC()':
threads.cpp:(.text+0x2ae): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `fiftPercentD()':
threads.cpp:(.text+0x396): undefined reference to `ceil'
/tmp/ccy8maS0.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

我已经将math.h库包含在我的程序中,并且我正在使用正确的语法进行调用:

ceil(tempA);

凡tempA是双倍持有我需要四舍五入的值。 有什么建议?我试过谷歌这些错误但是,像大多数错误一样,很难找到与你的错误具有相同模式的具体例子。

编辑:我已经解决了所有与ceil相关的错误(在命令行中使用-lm)但是最后一个错误仍然存​​在,我不知道它意味着什么,或者如何解决它。

1 个答案:

答案 0 :(得分:3)

将未定义的引用引用到ceil()

您似乎缺少与libm链接。

在您对-lm的调用中添加选项gcc可以解决此问题。


#include ing math.h是让编译器了解ceil()的定义。然后,链接器需要知道ceil()实现的实际位置,即libm

相关问题