LPI Linux Certification/Manage Shared Libraries

From Wikibooks, open books for an open world
< LPI Linux Certification
Jump to navigation Jump to search

Detailed Objective[edit]

Weight: 1

Candidates should be able to determine the shared libraries that executable programs depend on and install them when necessary.

  • Key knowledge area(s):
    • Identify shared libraries.
    • Identify the typical locations of system libraries.
    • Load shared libraries.
  • The following is a partial list of the used files, terms and utilities:
    • ldd
    • ldconfig
    • /etc/ld.so.conf

Shared libraries[edit]

A library is a set of functions that programs can use to implement their functionalities. When building (linking) a program, those libraries can be statically or dynamically linked to an executable. Static link means that the final program will contain the library function within its file. (lib.a) Dynamic link means that the needed libraries would need to be loaded into RAM when the program needs to be executed. (lib.so)

The default directories for all the standard libraries are:

  • /lib: Used mainly by /bin programs.
  • /usr/lib: Used mainly by /usr/bin programs.

The file /etc/ld.so.conf is used by the system to specify other library locations. To build a cache file used by the runtime loader of all the available libraies, use ldconfig. The file /etc/ld.so.cache will be generated.

Library dependencies[edit]

To print shared programs or library dependencies, use ldd.

ldd [-vdr] program|library


$ ldd -d -v /bin/cp
  libc.so.6 => /lib/libc.so.6 (0x40027000)
  /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

  Version information:
               libc.so.6 (GLIBC_2.1.3) => /lib/libc.so.6
               libc.so.6 (GLIBC_2.1) => /lib/libc.so.6
               libc.so.6 (GLIBC_2.2) => /lib/libc.so.6
               libc.so.6 (GLIBC_2.0) => /lib/libc.so.6
               ld-linux.so.2 (GLIBC_2.1.1) => /lib/ldlinux.so.2
               ld-linux.so.2 (GLIBC_2.2.3) => /lib/ldlinux.so.2
               ld-linux.so.2 (GLIBC_2.1) => /lib/ldlinux.so.2
               ld-linux.so.2 (GLIBC_2.2) => /lib/ld-linux.so.2
               ld-linux.so.2 (GLIBC_2.0) => /lib/ld-linux.so.2

Runtime loader[edit]

The runtime loader ld.so finds the needed library of a program and will load them into RAM. The search order of ld.so is:

  • The cache file /etc/ld.so.cache
  • The default directories /lib and /usr/lib.