Relationship between ldconfig and ld.so.cache

20,411

Solution 1

Linux programs are using libraries which are called shared objects. Shared objects have the extension .so. To see the S.O. usage of the command ls run ldd /bin/ls

  1. By default libs are stored in /lib /usr/lib and /usr/local/lib (/lib32, /lib64 for 32/64bit). The info where additional libs can be found are stored in /etc/ld.so.conf.d/. In there are single .conf files which contain pathes to specific libs ie. /opt/foo/lib. Since the lookup in /etc/ld.so.conf.d/ is very slow ldconfig generates the /etc/ld.so.cache file, which is a binary version of this which improves the lookup speed. To answer the first question. No keep the file.

  2. Yes, apt-get or dpkg (?) is triggering ldconfig. How it works - see 1.

  3. Yes, see 1.

I hope, I got it right. Feel free to correct me.

Solution 2

apt-get and dpkg both invoke ldconfig to rebuild the cache.

I imagine this is done at the end of every bulk operation but do not know for sure.

I don't think there is a way to remove specific data from the cache, it's just rebuilt e.g.:

rm /etc/ld.so.cache
ldconfig

You can use ldconfig -p to check the contents of the cache.

On my system ldconfig is invoked every reboot, but if /etc/ is being used for the cache then it is not being created from scratch each time; you'd have to rebuild it yourself if you want that.

If you remove some libraries manually, you will have to rebuild it.

Share:
20,411

Related videos on Youtube

Nirel
Author by

Nirel

Updated on September 18, 2022

Comments

  • Nirel
    Nirel over 1 year

    After I restart my computer, ld.so.cache still has the information in it, so my questions are as follows:

    1. Is the information always kept there? Isn't it being removed after restart or something like that? Like RAM or browser cache being deleted?

    2. After I have removed an application that installed some shared libraries, does it know to also remove the information from the ld.so.cache? If I use ldconfig will it remove the information? How does it actually work?

    3. If I am installing a program, how does my computer know to use the new libraries that had been added? After apt-get install is ldconfig run?