TrumanWong

ldconfig

Dynamic link library management commands

Supplementary instructions

The purpose of the ldconfig command is mainly to search for available files in the default search directories /lib and /usr/lib and the directories listed in the dynamic library configuration file /etc/ld.so.conf Shared dynamic link library (format such as lib*.so*), and then create the connection and cache files required by the dynamic loader (ld.so). The cache file defaults to /etc/ld.so.cache. This file saves a sorted list of dynamic link library names. In order to make the dynamic link library shared by the system, you need to run the dynamic link library management command ldconfig. This The executable program is stored in the /sbin directory.

ldconfig is usually run when the system starts, but when the user installs a new dynamic link library, this command needs to be run manually.

grammar

ldconfig [-v|--verbose] [-n] [-N] [-X] [-f CONF] [-C CACHE] [-r ROOT] [-l] [-p|--print-cache] [-c FORMAT] [--format=FORMAT] [-V] -?|--[help|--usage] path...

Options

-v or --verbose: When using this option, ldconfig will display the directories being scanned and the dynamic link libraries searched, as well as the names of the connections it creates.
-n: When using this option, ldconfig only scans the directories specified on the command line, not the default directories (/lib, /usr/lib), nor the directories listed in the configuration file /etc/ld.so.conf.
-N: This option instructs ldconfig not to rebuild the cache file (/etc/ld.so.cache). If the -X option is not used, ldconfig updates the file connection as usual.
-X: This option instructs ldconfig not to update the file connection. If the -N option is not used, the cached file will be updated normally.
-f CONF: This option specifies the configuration file of the dynamic link library as CONF, and the system default is /etc/ld.so.conf.
-C CACHE: This option specifies that the generated cache file is CACHE. The system default is /etc/ld.so.cache. This file stores a sorted list of shareable dynamic link libraries.
-r ROOT: This option changes the root directory of the application to ROOT (implemented by calling the chroot function). When this option is selected, the system default configuration file /etc/ld.so.conf actually corresponds to ROOT/etc/ld.so.conf. For example, when -r /usr/zzz is used, when the configuration file /etc/ld.so.conf is opened, the /usr/zzz/etc/ld.so.conf file is actually opened. Using this option can greatly increase the flexibility of dynamic link library management.
-l: Normally, ldconfig will automatically establish a connection to the dynamic link library when searching for the dynamic link library. When this option is selected, the expert mode will be entered and the connection needs to be set manually. General users do not need this option.
-p or --print-cache: This option instructs ldconfig to print out the names of all shared libraries saved in the current cache file.
-c FORMAT or --format=FORMAT: This option is used to specify the format used for cache files. There are three types: old (old format), new (new format) and compat (compatible format, this is the default format).
-V: This option prints out the version information of ldconfig and then exits.
-? or --help or --usage: These three options have the same effect. They all cause ldconfig to print out its help information and then exit.

Some things to note about ldconfig:

  1. There is no need to modify /etc/ld.so.conf when adding things to /lib and /usr/lib, but you need to adjust ldconfig after finishing, otherwise the library will not be found.
  2. When you want to add something to the above two directories, you must modify /etc/ld.so.conf and then call ldconfig, otherwise it will not be found.
  3. For example, if you install a mysql to /usr/local/mysql, mysql has a lot of libraries under /usr/local/mysql/lib, then you need to install /etc/ld.so.conf Add a line below /usr/local/mysql/lib, save it and run ldconfig so that the new library can be found when the program is running.
  4. If you want to put lib outside these two directories, but you don’t want to add anything to /etc/ld.so.conf (or you don’t have permission to add something). That's okay, just export a global variable LD_LIBRARY_PATH, and then when running the program, it will go to this directory to find the library. Generally speaking, this is only a temporary solution, used when there is no permission or temporary need.
  5. These things ldconfig does are related to the running time of the program and have nothing to do with the compilation time. You still need to add -L when compiling, don't get confused.
  6. In short, no matter what changes are made to the library, it is best to ldconfig, otherwise some unexpected results will occur. It won't take much time, but it will save a lot of trouble.
  7. Furthermore, the file header such as libdb-4.3.so will contain information related to the library name (that is, "libdb-4.3.so", which can be viewed with the strings command), so you can impersonate someone by simply modifying the file name. Recognized libraries (such as libdb-4.8.so) will not work. For this purpose, you can directly modify the configuration information in the Makefile of the compiled library and specify a special library name.