简体   繁体   English

/ usr / bin / ld:找不到共享库

[英]/usr/bin/ld: cannot find shared library

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_prog.c -L / usr / local / lib -llibcommon

It's giving 它给

/usr/bin/ld: cannot find -llibcommon.so / usr / bin / ld:找不到-llibcommon.so
collect2: ld returned 1 exit status 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
$

When you use the -l , you specify just the 'basic' library name: 使用-l ,仅指定“基本”库名:

-lcommon

This will track down libcommon.so in 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 ,但是...您无法解决所有问题)。

链接libcommon.so时使用-lcommon开关

try to export LD_LIBRARY_PATH pointing to the directory where you have kept the so files . 尝试导出LD_LIBRARY_PATH指向指向您保留so文件的目录。

export LD_LIBRARY_PATH = /pathofdirectorywheresofilesarekept 导出LD_LIBRARY_PATH = /目录路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM