5

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!

Community
  • 1
  • 1
ulyssis2
  • 1,165
  • 3
  • 10
  • 24

3 Answers3

2

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • Thanks 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.. – ulyssis2 Sep 17 '11 at 20:00
  • Is it `HOME` or `$HOME` in that string? – Mat Sep 18 '11 at 07:23
  • it 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 Sep 18 '11 at 19:57
1

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 for libc.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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • thanks 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 Sep 18 '11 at 19:47
  • it works now...so queer...I am so happy, thanks for your help! @Mat – ulyssis2 Sep 18 '11 at 20:14
1

to sum the solution:

  1. I add the path to ~./bashrc with:

    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/.../lindoapi/bin/linux64

  2. (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

ulyssis2
  • 1,165
  • 3
  • 10
  • 24