Linux modules and libraries

Dynamically linked libraries are linked and loaded at run time, either by “ld.so” or “ld-linux.so”, depending on how it was compiled: in a.out or ELF format.

Every program whenever they need a library, look through a known list of places to find the needed library. One place they look is “/etc/ld.so.cache”, which contains an ordered list of libraries to be searched for the needed module.

To find the libraries needed for a program, use the command “ldd”
Example:

# ldd /usr/bin/gimp
linux-gate.so.1 => (0x00110000)
libgimpwidgets-2.0.so.0 => /usr/lib/libgimpwidgets-2.0.so.0 (0x04b9a000)
libgimpmodule-2.0.so.0 => /usr/lib/libgimpmodule-2.0.so.0 (0x00a7a000)
libgimpcolor-2.0.so.0 => /usr/lib/libgimpcolor-2.0.so.0 (0x00a6d000)
libgimpthumb-2.0.so.0 => /usr/lib/libgimpthumb-2.0.so.0 (0x00264000)
libgimpmath-2.0.so.0 => /usr/lib/libgimpmath-2.0.so.0 (0x00a1e000)
libgimpconfig-2.0.so.0 => /usr/lib/libgimpconfig-2.0.so.0 (0x00a5d000)
libgimpbase-2.0.so.0 => /usr/lib/libgimpbase-2.0.so.0 (0x00a07000)
libgtk-x11-2.0.so.0 => /usr/lib/libgtk-x11-2.0.so.0 (0x06192000)
libgdk-x11-2.0.so.0 => /usr/lib/libgdk-x11-2.0.so.0 (0x06532000)
libatk-1.0.so.0 => /usr/lib/libatk-1.0.so.0 (0x005fd000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/libgdk_pixbuf-2.0.so.0 (0x00430000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x06169000)
libm.so.6 => /lib/libm.so.6 (0x00bff000)
libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0x00425000)
libcairo.so.2 => /usr/lib/libcairo.so.2 (0x0049e000)
libgthread-2.0.so.0 => /lib/libgthread-2.0.so.0 (0x00710000)
librt.so.1 => /lib/librt.so.1 (0x0098c000)
libart_lgpl_2.so.2 => /usr/lib/libart_lgpl_2.so.2 (0x0040c000)
libpangoft2-1.0.so.0 => /usr/lib/libpangoft2-1.0.so.0 (0x00449000)
libpango-1.0.so.0 => /usr/lib/libpango-1.0.so.0 (0x005b9000)
libgmodule-2.0.so.0 => /lib/libgmodule-2.0.so.0 (0x001ad000)
libdl.so.2 => /lib/libdl.so.2 (0x00c2a000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00dce000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00111000)
libdbus-glib-1.so.2 => /usr/lib/libdbus-glib-1.so.2 (0x0082f000)
libdbus-1.so.3 => /lib/libdbus-1.so.3 (0x00854000)
libgobject-2.0.so.0 => /lib/libgobject-2.0.so.0 (0x00375000)
libglib-2.0.so.0 => /lib/libglib-2.0.so.0 (0x001c3000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00c46000)
libc.so.6 => /lib/libc.so.6 (0x00aa9000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00c6d000)
libXfixes.so.3 => /usr/lib/libXfixes.so.3 (0x0019b000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00d71000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x001a0000)
libXinerama.so.1 => /usr/lib/libXinerama.so.1 (0x001a9000)
libXi.so.6 => /usr/lib/libXi.so.6 (0x00493000)
libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0x001b0000)
libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x001b7000)
libz.so.1 => /lib/libz.so.1 (0x00c31000)
/lib/ld-linux.so.2 (0x00a8a000)
libexpat.so.0 => /lib/libexpat.so.0 (0x00d83000)
libnsl.so.1 => /lib/libnsl.so.1 (0x00814000)
libcap.so.1 => /lib/libcap.so.1 (0x00a29000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00c68000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00c60000)

————————————————————————

ld.so.cache contains a complete list of all the shared object libraries that ld.so or ld-linux.so will search in machine readable format.

Suppose that I install a new application in my machine. I also add a library, say, libZYZ.so.2 needed for that application under the location /usr/local/lib/XYZ/lib/ directory. But if “/etc/ld.so.conf file doesn’t contain a reference to that directory, the library will never get into the cache “/etc/ld.so.cache”, and “ld.so” and “ld-linux.so” will never be able to access that library from cache for running the newly installed application.

How to fix the above said problem?

Simple. Add the directory “/usr/local/lib/XYZ/lib/” to the “/etc/ld.so.conf” file and then – as root – run the “ldconfig” program so it rebuilds the cache “/etc/ld.so.cache”.

To view the contents of “ld.so.cache” use the command “ldconfig -p”. This will give the output with the following kind of first line “1301 libs found in cache `/etc/ld.so.cache'”

On Linux, run “/sbin/ldconfig -v” as root to see all the shared libraries that applications make use of day in and day out

If you need further assistance, please do not hesitate to contact us.

Written by actsupp-r0cks