Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

c++ - usr / bin / ld:找不到-l <nameOfTheLibrary>(usr/bin/ld: cannot find -l<nameOfTheLibrary>)

I'm trying to compile my program and it returns this error :

(我正在尝试编译我的程序,它返回此错误:)

usr/bin/ld: cannot find -l<nameOfTheLibrary>

in my makefile I use the command g++ and link to my library which is a symbolic link to my library located on an other directory.

(在我的makefile文件中,我使用命令g++并链接到我的库,这是到另一个目录中我的库的符号链接。)

Is there an option to add to make it work please?

(是否可以添加选项以使其正常工作?)

  ask by ZoOo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!

(瞧!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...