C语言 /usr/bin/ld: 找不到共享库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18639723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/usr/bin/ld: cannot find shared library
提问by user2732944
I am having libcommon.so in the /usr/local/lib and I am linking this library in my program.
我在 /usr/local/lib 中有 libcommon.so 并且我正在我的程序中链接这个库。
gcc -o test test_prog.c -L/usr/local/lib -llibcommon.so
gcc -o test test_prog.c -L/usr/local/lib -llibcommon.so
and I have tried this too
我也试过这个
gcc -o test test_prog.c -L/usr/local/lib -llibcommon
gcc -o test test_prog.c -L/usr/local/lib -llibcommon
It's giving
它给
/usr/bin/ld: cannot find -llibcommon.so
collect2: ld returned 1 exit status
/usr/bin/ld: 找不到 -llibcommon.so
collect2: ld 返回 1 个退出状态
It is there:
它在那里:
$ locate libcommon.so
/usr/local/lib/libcommon.so
/usr/local/lib/libcommon.so.0
/usr/local/lib/libcommon.so.0.1.0
$
回答by Jonathan Leffler
When you use the -l, you specify just the 'basic' library name:
当您使用 时-l,您只需指定“基本”库名称:
-lcommon
This will track down libcommon.soin some directory.
这将libcommon.so在某个目录中进行跟踪。
You told the compiler to try and find liblibcommon.so.so(and liblibcommon.so) and it probably couldn't...indeed, you wouldn't be asking the question if it could.
您告诉编译器尝试查找liblibcommon.so.so(和liblibcommon.so),但它可能无法……事实上,如果可以,您就不会问这个问题。
Some GNU programs build a library libiberty.so(or its equivalent), so the link lines using the library link with:
一些 GNU 程序构建了一个库libiberty.so(或其等效的),因此使用库的链接行链接:
-liberty
(which is funny; GNU would really rather it was +liberty, but ... you can't fix everything).
(这很有趣;GNU 真的宁愿它是+liberty,但是......你不能解决所有问题)。
回答by sr01853
Use -lcommonswitch when you link libcommon.so
-lcommon链接时使用开关libcommon.so
回答by vineet pant
try to export LD_LIBRARY_PATH pointing to the directory where you have kept the so files .
尝试导出指向保存 so 文件的目录的 LD_LIBRARY_PATH。
export LD_LIBRARY_PATH = /pathofdirectorywheresofilesarekept
导出 LD_LIBRARY_PATH = /pathofdirectorywheresofilesarekept

