Table of Content

Weight: 1

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

Key Knowledge Areas:

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

Terms and Utilities:

ldd
ldconfig
/etc/ld.so.conf
LD_LIBRARY_PATH

ldd

/usr/sbin# ldd /bin/ln

so means shared objects or dynamic libraries 
ls -l /lib/x86_64-linux-gnu/libc.so.6 /lib64/ld-linux-x86-64.so.2

/lib64/ld-linux-x86-64.so.2 --list /bin/ln

ldconfig

/etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf

ls -l /etc/ld.so.conf.d
-rw-rw-r-- 1 root root 38 Nov 24  2014 fakeroot-x86_64-linux-gnu.conf
-rw-r--r-- 1 root root 44 Aug  9  2009 libc.conf
-rw-r--r-- 1 root root 68 Mar 25  2015 x86_64-linux-gnu.conf

- after change on config file need to run ldconfig to rebuild ld.so.cache
- ldconfig generate necessary links and cache to recently used shared libraries in /etc/ld/so.cache
- dynamic loader uses cached info from ld.so.cache to locate files that are to be dynamically loaded and linked

ldconfig -p  # print ld.so.cache

lib path

export LD_LIBRARY_PATH=/usr/local/testlib:/opt/newlab

Quiz questions

1. Why do shared libraries include version numbers?
2. Why do programs use shared libraries, rather than including the library code in the
executable file?
3. What is the purpose of LD_PRELOAD?
4. When is it necessary to run ldconfig?
5. What is LD_LIBRARY_PATH, and what does it configure?
6. Where are system libraries found on a Linux system, and what is the purpose of each
location?

Answers to quiz questions

1. This makes it possible to use new programs together with programs which use older
libraries.
2. Including the code from shared libraries would make them bulky, and the system works
better with a single copy of library code being shared between programs.
3. This variable can be set to the name of a library which overrides functions from the
standard libraries.
4. It's the search path for the system libraries. It determines which directories are searched when a dynamic executable is loaded.
5. LD_LIBRARY_PATH is an environment variable. It determines the directories in which
the dynamic loader will search for libraries.
6. /lib contains libraries required by the system commands in /bin. /usr/lib contains most
system libraries. A complete list of additional directories is in /etc/ld.so.conf, largely for X
and its applications.