error while loading shared libraries
Solution 1
You need to have the directory where the .so
files live in in runtime linker's search path.
You can do that by changing the LD_LIBRARY_PATH
environment variable like this:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/lindoapi/bin/linux64
before starting your executable.
Solution 2
If you are not going to install libraries currently under /home/li/work/tools/lindo/lindoapi/bin/linux64
into a system directory (/usr/lib
, /usr/local/lib
, etc.), then it is better to simply link the application such that it will just work(TM):
gcc -o ex_addinst ./ex_addinst.o \
-L/home/li/work/tools/lindo/lindoapi/bin/linux64 \
-Wl,-rpath=/home/li/work/tools/lindo/lindoapi/bin/linux64 \
-m64 -llindo64 -lmosek64 -lconsub3 -lc -ldl \
-lm -lguide -lpthread -lsvml -limf -lirc
This is preferable to always having to set LD_LIBRARY_PATH
, because
- other people can run your executable (without having to set
LD_LIBRARY_PATH
) and, - it doesn't slow down all the other applications (otherwise they will all search
LD_LIBRARY_PATH
forlibc.so.6
, etc.)
The reason your LD_LIBRARY_PATH
setting didn't work (comment to Mat's answer) is that you used HOME
where /home
was intended.
Solution 3
to sum the solution:
-
I add the path to ~./bashrc with:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/.../lindoapi/bin/linux64
-
(after generating .o file)link the objective file with:
g++ -o ex_addinst ./ex_addinst.o -L/home/.../lindoapi/bin/linux64 -m64 -llindo64 -lmosek64 -lconsub3 -lc -ldl -lm -lguide -lpthread -lsvml -limf -lirc
Related videos on Youtube
ulyssis2
Updated on June 04, 2022Comments
-
ulyssis2 almost 2 years
Thank you guys answering my previous problem on undefined reference to function. As you suggested, the reason under the problem is not linking the libraries. Now I have generated the executable file with: (the version of my g++ and gcc is 4.4.5. I am using Ubuntu 10.10.)
g++ -o ex_addinst ./ex_addinst.o -L/home/li/work/tools/lindo/lindoapi/bin/linux64 -m64 -llindo64 -lmosek64 -lconsub3 -lc -ldl -lm -lguide -lpthread -lsvml -limf -lirc
But there comes another problem, when I run the executable file with
./ex_addinst
errors appear: (I am not sure I should start a new problem or not currently....)
./ex_addinst: error while loading shared libraries: liblindo64.so.6.0: cannot open shared object file: No such file or directory
But liblindo64.so.6.0 exists in the folder of the lib ~/lindoapi/bin/linux64 which contains following files:
libconsub3.so libirc.so liblindojni.so libmosek64.so.5.0 lindo.par libguide.so liblindo64.so liblindojni.so.6.0.3 libsvml.so placeholder libimf.so liblindo64.so.6.0 libmosek64.so lindoapivars.sh runlindo
I have created a symbolic link between liblindo.so.6.0 and liblindo.so:
ln -sf liblindo64.so.6.0 liblindo64.so
There is '-llindo64' is the g++ command, so I thought liblindo64.so.6.0 should have been linked. I have tried to change -L to -Llib, but doesn't help.
Can anyone tell me what is wrong here? Thanks!
-
ulyssis2 over 12 yearsThanks Mat, in the directionary HOME/.../lindoapi/bin/linux64, there is a lindoapivars.sh file, where the LD_LIBRARY_PATH has been modified as: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:HOME/li/work/tools/lindo/lindoapi/bin/linux64 export LD_LIBRARY_PATH. But he problem still appears..
-
Mat over 12 yearsIs it
HOME
or$HOME
in that string? -
ulyssis2 over 12 yearsthanks friend, with your suggestion, I added the library into ~/.bashrc: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/li/work/tools/lindo/lindoapi/bin/linux64, but the problem is still the same. Am I correct to change ~/.bashrc ? I think I am suing non-login shell so I think only ~/.bashrc is read.
-
ulyssis2 over 12 yearsit is $HOME, sorry, my typo. As there is the content in lindoapivars.sh, I think this is not the right place to change this variable.
-
ulyssis2 over 12 yearsit works now...so queer...I am so happy, thanks for your help! @Mat