Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/usr/bin/ld: cannot find

Tags:

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

like image 309
Alwin Doss Avatar asked Mar 16 '11 17:03

Alwin Doss


People also ask

How do you resolve usr bin Ld Cannot find?

“/usr/bin/ld cannot find -lltdl” Error and Solution The “/usr/bin/ld cannot find -lltdl” error is related to the C development library named ltdl-dev . So installing the libtdl-dev can resolve this error.

What is Ldflags in Makefile?

LDFLAGS: Extra flags to give to compilers when they are supposed to invoke the linker, 'ld', such as -L. Libraries (-lfoo) should be added to the LDLIBS variable instead. LDLIBS: Library flags or names given to compilers when they are supposed to invoke the linker, 'ld'.


2 Answers

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

like image 90
Dr. Snoopy Avatar answered Sep 16 '22 17:09

Dr. Snoopy


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 
like image 31
otter Avatar answered Sep 20 '22 17:09

otter