/usr/bin/ld: cannot find shared library

拜拜、爱过 提交于 2020-01-03 04:50:10

问题


I am having libcommon.so in the /usr/local/lib and I am linking this library in my program.

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

It's giving

/usr/bin/ld: cannot find -llibcommon.so
collect2: ld returned 1 exit status

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
$

回答1:


When you use the -l, you specify just the 'basic' library name:

-lcommon

This will track down libcommon.so in some directory.

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.

Some GNU programs build a library libiberty.so (or its equivalent), so the link lines using the library link with:

-liberty

(which is funny; GNU would really rather it was +liberty, but ... you can't fix everything).




回答2:


Use -lcommon switch when you link libcommon.so




回答3:


try to export LD_LIBRARY_PATH pointing to the directory where you have kept the so files .

export LD_LIBRARY_PATH = /pathofdirectorywheresofilesarekept



来源:https://stackoverflow.com/questions/18639723/usr-bin-ld-cannot-find-shared-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!