To figure out what the linker is looking for, run it in verbose mode.
(要弄清楚链接程序在寻找什么,请在详细模式下运行它。)
For example, I encountered this issue while trying to compile MySQL with ZLIB support.
(例如,当我尝试使用ZLIB支持编译MySQL时遇到了这个问题。)
I was receiving an error like this during compilation: (我在编译期间收到这样的错误:)
/usr/bin/ld: cannot find -lzlib
I did some Googl'ing and kept coming across different issues of the same kind where people would say to make sure the .so file actually exists and if it doesn't, then create a symlink to the versioned file, for example, zlib.so.1.2.8.
(我做了一些Googl'ing操作,并不断遇到同类问题,人们会说要确保.so文件确实存在,如果不存在,则创建指向版本文件的符号链接,例如zlib。所以1.2.8。)
But, when I checked, zlib.so DID exist. (但是,当我检查时,zlib.so DID存在。)
So, I thought, surely that couldn't be the problem. (所以,我想,那肯定不是问题。)
I came across another post on the Internets that suggested to run make with LD_DEBUG=all:
(我在互联网上遇到了另一条建议使用LD_DEBUG = all运行make的帖子:)
LD_DEBUG=all make
Although I got a TON of debugging output, it wasn't actually helpful.
(尽管我得到了大量调试信息,但实际上并没有帮助。)
It added more confusion than anything else. (它比其他任何事情都增加了混乱。)
So, I was about to give up. (所以,我正要放弃。)
Then, I had an epiphany.
(然后,我顿悟了。)
I thought to actually check the help text for the ld command: (我认为实际上要检查ld命令的帮助文本:)
ld --help
From that, I figured out how to run ld in verbose mode (imagine that):
(由此,我想出了如何在详细模式下运行ld(想象一下):)
ld -lzlib --verbose
This is the output I got:
(这是我得到的输出:)
==================================================
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.a failed
attempt to open /usr/local/lib64/libzlib.so failed
attempt to open /usr/local/lib64/libzlib.a failed
attempt to open /lib64/libzlib.so failed
attempt to open /lib64/libzlib.a failed
attempt to open /usr/lib64/libzlib.so failed
attempt to open /usr/lib64/libzlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.a failed
attempt to open /usr/local/lib/libzlib.so failed
attempt to open /usr/local/lib/libzlib.a failed
attempt to open /lib/libzlib.so failed
attempt to open /lib/libzlib.a failed
attempt to open /usr/lib/libzlib.so failed
attempt to open /usr/lib/libzlib.a failed
/usr/bin/ld.bfd.real: cannot find -lzlib
Ding, ding, ding...
(叮,叮...)
So, to finally fix it so I could compile MySQL with my own version of ZLIB (rather than the bundled version):
(因此,最后修复它,以便可以使用自己的ZLIB版本(而不是捆绑版本)来编译MySQL:)
sudo ln -s /usr/lib/libz.so.1.2.8 /usr/lib/libzlib.so
Voila!
(瞧!)