ldconfig – Dynamic Link Library Management Command

ldconfig is a command-line tool in Linux used to update the shared library cache. It is responsible for configuring the dynamic linker runtime bindings. The dynamic linker is responsible for resolving symbols at runtime, which means that it loads shared libraries and links them with the executable file. The ldconfig command is used to manage the shared libraries and their dependencies in a system.

Overview

The ldconfig command is used to update the shared library cache. It scans the directories specified in the /etc/ld.so.conf file and the trusted directories (/lib, /usr/lib, /usr/local/lib, etc.) to find shared libraries. It then creates a cache of the shared libraries and their dependencies. When a program is executed, the dynamic linker uses this cache to locate the required shared libraries.

Syntax

ldconfig [-nNvXV] [-f conf] [-C cache] [-r root] [-l loader] [-p] [-c] [-d] [-D] [-A] [-q] [-a arch] [-R relro] [-u] [directories...]

Examples

  1. Update the shared library cache:
sudo ldconfig
  1. Add a directory to the list of directories to be searched for shared libraries:
sudo ldconfig /usr/local/lib
  1. Show the contents of the shared library cache:
ldconfig -p
  1. Update the cache for a specific path:
sudo ldconfig /usr/local/lib64/

Specific Use Cases

The ldconfig command is useful in the following scenarios:

  • When a new shared library is installed, ldconfig must be run to update the cache so that the dynamic linker can find it.
  • When a shared library is removed, ldconfig must be run to remove the library from the cache.
  • When a library is upgraded, ldconfig must be run to ensure that the latest version of the library is used.

Options

The following table lists the available options for the ldconfig command:

Option Description
-n Do not execute anything; just print what would be done.
-N Do not update the cache.
-v Verbose output.
-X Do not use cached data.
-V Print the version number and exit.
-f conf Use the specified configuration file instead of /etc/ld.so.conf.
-C cache Use the specified cache file instead of /etc/ld.so.cache.
-r root Set the root directory.
-l loader Set the dynamic linker.
-p Print the contents of the cache.
-c Create the cache.
-d Delete the cache.
-D Show the differences between the old and new cache.
-A Add the specified directories to the cache.
-q Quiet mode.
-a arch Set the architecture.
-R relro Set the relro mode.
-u Remove unused cache entries.

Troubleshooting Tips

  • If a shared library is not found, check that it is installed and that its directory is listed in the /etc/ld.so.conf file.
  • If a shared library is found but not used, check that it is the correct version and that it is listed before any other versions in the /etc/ld.so.conf file.
  • If a shared library is not updated after an upgrade, run ldconfig to update the cache.

Notes

  • The ldconfig command should be run as root or with sudo privileges.
  • The ldconfig command is part of the GNU C Library (glibc) package.