【发布时间】:2012-04-13 15:23:28
【问题描述】:
这很奇怪,因为我能够通过删除对 libm 的引用来消除下面的错误。
gcc -o example example.o -Wl -L/home/kensey/cdev/lib -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -L/usr/lib/x86_64-linux-gnu -lm -lrt -ldl -lcdev -L/home/kensey/www.tools/gplot-lib -lgplot -L/home/kensey/www.tools/gd1_3ret -lgd -lxml2 -lcurl
/usr/bin/ld: /home/kensey/www.tools/gplot-lib/libgplot.a(set.o): undefined reference to symbol 'floor@@GLIBC_2.2.5'
/usr/bin/ld: note: 'floor@@GLIBC_2.2.5' is defined in DSO /usr/lib/x86_64-linux-gnu/libm.so so try adding it to the linker command line
/usr/lib/x86_64-linux-gnu/libm.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
因此,如果我删除命令的 -lm 部分,我不会收到错误消息。但是,我想知道是否有人知道为什么删除对所需库的引用会解决此问题。链接器如何知道要查看哪个库?另外 - 有没有办法查询构建的可执行文件并说“您解决了对“地板”的引用是哪个库?显然,发生了一些我不明白的事情,这让我很困扰......
【问题讨论】:
-
-Wl选项后面通常跟一个逗号(将逗号后面的文本作为选项传递给链接器),你打算用它做什么?