gcc: linked libraries in /usr/local/lib are not found, but /etc/ld/so.conf.d/libc.conf lists it?

10,717

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).

Share:
10,717

Related videos on Youtube

Metalskin
Author by

Metalskin

I've been in the IT industry for longer than I care to admit, working on various platforms using many different languages. My main focus has been business software, however I have done real time mission critical systems, embedded systems, integration with PLCs and some comms related stuff. However since 2007 I have focused on software design, now I only code for fun. My main interest at the moment is html5, css3, js and node.js.

Updated on July 14, 2022

Comments

  • Metalskin
    Metalskin almost 2 years

    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.

    • Basile Starynkevitch
      Basile Starynkevitch over 11 years
      Did you run ldconfig after every change of (i.e. write into) /usr/local/lib ?
    • Metalskin
      Metalskin over 11 years
      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.