/usr/bin/ld: cannot find

落花浮王杯 提交于 2020-01-01 01:25:10

问题


I created a .so file and put it in the location /opt/lib and added this path to LD_LIBRARY_PATH now after this when I try to compile my main program with the following command:

g++ -Wall -I/home/alwin/Development/Calculator/ main.cpp -lcalc -o calculator

I get the following error:

/usr/bin/ld: cannot find -lcalc
collect2: ld returned 1 exit status

Can someone help me with this. I created the shared library using the code blocks IDE


回答1:


Add -L/opt/lib to your compiler parameters, this makes the compiler and linker search that path for libcalc.so in that folder.




回答2:


When you make the call to gcc it should say

g++ -Wall -I/home/alwin/Development/Calculator/ -L/opt/lib main.cpp -lcalc -o calculator

not -libcalc.so 

I have a similar problem with auto-generated makes.

You can create a soft link from your compile directory to the library directory. Then the library becomes "local".

cd /compile/directory

ln -s  /path/to/libcalc.so libcalc.so



回答3:


You need to add -L/opt/lib to tell ld to look there for shared objects.




回答4:


@Alwin Doss You should provide the -L option before -l. You would have done the other way round probably. Try this :)



来源:https://stackoverflow.com/questions/5329638/usr-bin-ld-cannot-find

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