Matthew Matthew - 1 year ago 124
Linux Question

ld cannot find libraries even though they exist

EDIT: Apparantly ~ doesn't work here and only in the shell, replace ~ with '$HOME' and it should work, thanks for everybody who answered.

Trying to compile a project here but it seems it can't find the libraries even though they exist, here is the output of my line and proof that the libraries exist.

pi@raspberrypi ~/Car $ g++ Car.cpp -I~/git/robidouille/raspicam_cv -L~/git/robidouille/raspicam_cv -lraspicamcv -L~/git/userland/build/lib -lmmal_core -lmmal -lmmal_util -lvcos -lbcm_host -I/usr/include/opencv -lopencv_highgui -lopencv_core -lopencv_video -lopencv_imgproc -lpthread -lm
/usr/bin/ld: cannot find -lraspicamcv
/usr/bin/ld: cannot find -lmmal_core
/usr/bin/ld: cannot find -lmmal
/usr/bin/ld: cannot find -lmmal_util
/usr/bin/ld: cannot find -lvcos
/usr/bin/ld: cannot find -lbcm_host
collect2: ld returned 1 exit status
pi@raspberrypi ~/Car $ find ~/ -name
pi@raspberrypi ~/Car $ find ~/ -name
pi@raspberrypi ~/Car $ find ~/ -name
pi@raspberrypi ~/Car $

EDIT: Tried doing

ld -L~/git/userland/build/lib -lmmal_core --verbose

and it gave me

attempt to open ~/git/userland/build/lib/ failed

but ~/git/userland/build/lib/ does infact exist, so for some reason it can't seem to open the file while it exists.

Answer Source

Expanding "~" to your home directory is a feature of the shell, and it is not expanded "inside" a parameter such as -I~/git/robidouille/raspicam_cv.

When the linker goes looking for the library, it doesn't ask your shell where it is — it tries to find the literal path "~/git/robidouille/raspicam_cv", which doesn't exist.

Replace "~" with "$HOME", which will be expanded by the shell.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download