14

I've got a problem with shared libraries and gcc. At first I couldn't run my compiled program because I was getting the following error: gcc error while loading shared libraries.

I did some searching and found that this is because the shared library cannot be found. However I had already identified that the shared library is in /usr/local/lib, which AFAICT is a commonly used directory for shared libraries and should work from the get go.

I read that you can set LD_LIBRARY_PATH, which worked for me. However I do not wish to set this each time I want to run my program.

Further searching suggested editing ld.so.conf. When I looked in this it had the following:

include /etc/ld.so.conf.d/*.conf

Looking in the ld.so.conf.d directory shows me a range of files, including libc.conf. Inside this file is the following:

/usr/local/lib

So my question is, why do I need to manually set LD_LIBRARY_PATH when the ld.so.conf appears to use the libc.conf which includes /usr/local/lib?

Is there something that I'm missing here that must be configured first? Is there an option at compile time that I'm missing?

I should note that to compile, I had to specify the path to the library, I don't know if this is a symptom of my problem or normal behaviour.

I should also note that this is a concern for me for when I deploy my software on other systems. I would have thought that I should be able to put the .so in the appropriate place and install my program without messing with ld.so.conf.

I hope this is the proper forum for this question, I read the FAQ and I think it's ok.

Cheers.

Metalskin
  • 3,998
  • 5
  • 37
  • 61
  • 1
    Did you run `ldconfig` after every change of (i.e. write into) `/usr/local/lib` ? – Basile Starynkevitch Sep 02 '12 at 07:27
  • I thought ldconfig only had to be run after changing the conf files, not when putting a file into /usr/local/lib ? – Metalskin Sep 02 '12 at 08:39
  • 1
    I think I answered my own question, googled ldconfig and it looks like there is a cache that needs to be updated. I did a ldconfig -p and grep'd for the library and it's not there, so looks like the problem is the cache that ldconfig manages. Thanks Basile! Should I now answer my own question? Other questions in this area do not make clear that ldconfig is required to be run when new libs are added, they read that you run when you change the conf files. – Metalskin Sep 02 '12 at 08:43

1 Answers1

18

You should run ldconfig (as root) after every change of the directories configured via /etc/ld.so.conf or under /etc/ld.so.conf.d/, in particular in your case after every update inside /usr/local/lib (e.g. after every addition or update of some shared libraries there).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547