这很奇怪,因为我通过删除对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
,就不会出现错误。然而,我想知道为什么删除所需的库的引用就能解决这个问题。链接器如何知道要查找哪个库?另外,有没有一种方法可以查询已构建的可执行文件并说“你是如何解析对'floor'的引用的”?显然,有些事情我不理解,这让我感到困扰...