I'm trying to compile my program and it returns this error :
usr/bin/ld: cannot find -l<nameOfTheLibrary>
in my makefile I use the command g++
and link to my library which is a symbolic link to my library located on an other directory.
Is there an option to add to make it work please?
Check the location of your library, for example lxxx.so:
If it is not in the
/usr/lib
folder, type this:Done.
Apart from the answers already given, it may also be the case that the *.so file exists but is not named properly. Or it may be the case that *.so file exists but it is owned by another user / root.
Issue 1: Improper name
If you are linking the file as
-l<nameOfLibrary>
then library file name MUST be of the formlib<nameOfLibrary>
If you only have<nameOfLibrary>.so
file, rename it!Issue 2: Wrong owner
To verify that this is not the problem - do
If the file is owned by root or another user, you need to do
My issue was that I renamed the parent directory of the program I was running (
mpicc
from MVAPICH), and it somehow screwed up the binary. Even prepending LD_LIBRARY_PATH wasn't enough and I had to re-compile it to the correct path.When you compile your program you must supply the path to the library; in g++ use the -L option:
There does not seem to be any answer which addresses the very common beginner problem of failing to install the required library in the first place.
On Debianish platforms, if
libfoo
is missing, you can frequently install it with something likeThe
-dev
version of the package is required for development work, even trivial development work such as compiling source code to link to the library.The package name will sometimes require some decorations (
libfoo0-dev
?foo-dev
without thelib
prefix? etc), or you can simply use your distro's package search to find out precisely which packages provide a particular file.(If there is more than one, you will need to find out what their differences are. Picking the coolest or the most popular is a common shortcut, but not an acceptable procedure for any serious development work.)
For other architectures (most notably RPM) similar procedures apply, though the details will be different.
First, you need to know the naming rule of
lxxx
:lc
meanslibc.so
,lltdl
meanslibltdl.so
,lXtst
meanslibXts.so
.So, it is
lib
+lib-name
+.so
Once we know the name, we can use
locate
to find the path of thislxxx.so
file.If you cannot find it, you need to install it by
yum
(I use CentOS). Usually you have this file, but it does not link to right place.Link it to the right place, usually it is
/lib64
or/usr/lib64
$ sudo ln -s /home/user/anaconda3/lib/libiconv.so /usr/lib64/
Done!
ref: https://i-pogo.blogspot.jp/2010/01/usrbinld-cannot-find-lxxx.html