1

Suppose I have /a/lib/dir that has files

-rwxrwxr-x libboost_signals.so
-rwxrwxr-x libboost_signals.so.1.55.0

And I create a file: /etc/ld.so.conf.d/testlib.conf with content

/a/lib/dir

And run

sudo ldconfig
sudo ldconfig -v | head

libboost_signals.so.1.55.0 -> libboost_signals.so.1.55.0

Since ldconfig create a link libboost_signals.so.1.55.0 not libboost_signals.so,

I can't use -lboost_signals when use g++ to compile the source code.

But -L/a/lib/dir/ -lboost_signals is ok.


Edit the .bashrc file as:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/a/lib/dir

then

source .bashrc

will be the same result.

So what is the correct way to add system LD_LIBRARY_PATH?

Aylwyn Lake
  • 1,501
  • 3
  • 17
  • 34

2 Answers2

0

Once you add directory to ldconfig, or to LD_LIBRARY_PATH, it knows all the shared libs in this directory. It includes the both shared libs. If the lib appears twice in two paths, it will take the later.

ldconfig just menage the name resolving of shared libs. it doesn't create any links. you should create the links.

You find the -lboost_signals because you have the libboost_signals.so.

libboost_signals.so should be soft link to libboost_signals.so.1.55.0. But it look like you copied it. if you replace the libboost_signals.so.1.55.0 your programs will continue to use the old libboost_signals.so

Try this:

cd /a/lib/dir
rm libboost_signals.so
link -s libboost_signals.so.1.55.0 libboost_signals.so

EDIT: run ldconfig like this:

sudo ldconfig -p | grep libboost_signals

I guess you will see the both files

SHR
  • 7,149
  • 9
  • 32
  • 50
  • I've try this before asking this question. it always show `libboost_signals.so.1.55.0 -> libboost_signals.so.1.55.0`. And `man ldconfig` shows `ldconfig creates, updates, and removes the necessary links and cache` – Aylwyn Lake Jan 13 '14 at 11:04
  • Yes, `-p` do show the `libboost_signals.so`, But still not work. Thank you. I'm sorry for reply until now. I think Maxim Yegorushkin is right. – Aylwyn Lake Jan 21 '14 at 09:25
0

I can't use -lboost_signals when use g++ to compile the source code.

But -L/a/lib/dir/ -lboost_signals is ok.

LD_LIBRARY_PATH and /etc/ld.so.conf.d control the behaviour of the run-time linker ld.so only and do not affect the linking of the object files and libraries done by ld, this is why -L/a/lib/dir/ must be used.

There is no config file or environment variable to add to ld linker path. People normally hard-code extra linker paths in the makefile. Makefiles often consider LDFLAGS environment variable though.

Community
  • 1
  • 1
Maxim Egorushkin
  • 119,842
  • 14
  • 147
  • 239