102.3 Manage Shared Libraries

Key Knowlage Areas

  • Identify shared libraries
  • Identify the typical locations of system libraries
  • Load shared libraries

Terms and Utilties

  • ldd
  • ldconfig
  • /etc/ld.so.conf


Display required shared libraries by each specified program. Results in the name of the required library and where the library is expected to be in the filesystem.

ldd programs
ldd /usr/bin/vim.basic
	linux-gate.so.1 =>  (0xb7738000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb76da000)
	libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb76b8000)
	libselinux.so.1 => /lib/i386-linux-gnu/libselinux.so.1 (0xb7694000)
	libacl.so.1 => /lib/i386-linux-gnu/libacl.so.1 (0xb768b000)
	libgpm.so.2 => /usr/lib/i386-linux-gnu/libgpm.so.2 (0xb7684000)
	libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb767f000)
	libpython2.7.so.1.0 => /usr/lib/i386-linux-gnu/libpython2.7.so.1.0 (0xb7350000)
	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7333000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7184000)
	/lib/ld-linux.so.2 (0xb7739000)
	libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb7146000)
	libattr.so.1 => /lib/i386-linux-gnu/libattr.so.1 (0xb7140000)
	libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb7126000)
	libutil.so.1 => /lib/i386-linux-gnu/libutil.so.1 (0xb7121000)


The shared object dynamic linker ld.so looks for required libraries a dynamically linked program needs. If ld.so doesn't find the necessary libraries it fails and the program won't run.

To tell ld.so where to look for libraries one way is to add colon-seperated lists of directories to LD_LIBRARY_PATH. ld.so will look into every directory it finds there.

ldconfig & ld.so.conf

Creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).

ldconfig uses the following config files/directories:

├── fakeroot-i386-linux-gnu.conf
├── i386-linux-gnu_EGL.conf -> /etc/alternatives/i386-linux-gnu_egl_conf
├── i386-linux-gnu_GL.conf -> /etc/alternatives/i386-linux-gnu_gl_conf
├── i686-linux-gnu.conf
└── libc.conf

The index itself is stored in /etc/ld.so.cache - a binary file.

To add new libraries to the cache, first add the directory path to the config file, then run ldconfig to update the cache!

Check what's currently in the cache:

ldconfig -p
959 libs found in cache `/etc/ld.so.cache'
        libzvbi.so.0 (libc6) => /usr/lib/i386-linux-gnu/libzvbi.so.0
        libzvbi-chains.so.0 (libc6) => /usr/lib/i386-linux-gnu/libzvbi-chains.so.0
        libzephyr.so.4 (libc6) => /usr/lib/i386-linux-gnu/libzephyr.so.4
        libzbar.so.0 (libc6) => /usr/lib/libzbar.so.0
        libz.so.1 (libc6) => /lib/i386-linux-gnu/libz.so.1


Rebuild the cache:

lpic/102.3.txt · Last modified: 2014-06 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready