我正在编写一个处理线程的程序,我几乎已经完全可以工作了。不幸的是,我遇到了一个错误(重复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 ),但是最后一个错误仍然存在,我不知道它是什么意思,也不知道如何修复它。
发布于 2012-11-09 01:41:52
引用未定义的对ceil()的引用
您似乎缺少与libm的链接。
将选项-lm添加到对gcc的调用中应该可以解决此问题。
#includeing math.h是为了让编译器知道ceil()的定义,然后链接器需要知道ceil()的实现实际驻留在哪里,即在libm中。
https://stackoverflow.com/questions/13294582
复制相似问题