(transfer) Linux ldconfig and LDD instructions

Original text: https://blog.csdn.net/iamzhangzhuping/article/details/49203981

I. ldconfig

      ldconfigIs a dynamic link library management command, in order to make the dynamic link library shared by the system, also need to run the dynamic link library management command – ldconfig. The purpose of the ldconfig command is mainly in the default search directory (/lib and /usr/lib) and dynamic library allocation.Locate the directory listed in the file / etc / ld. so. conf, search for a shared dynamic link library (in the format lib *. so *) and create the connection and cache files needed for dynamic loading program (ld. so). The cache file defaults to / etc / LD.so.cache, this file saves the list of dynamically linked library names.

      linuxThe shared library mechanism uses a cache-like mechanism, which stores the library information in / etc / ld. so. cache. When the program connects, it first looks in this file, and then looks in the path of ld. so. conf. That’s why it changed LD.so.conf has to re run the reason for ldconfig.

ldconfigSeveral points to note:

1)You don’t have to modify / etc / ld. so. conf to add things to / lib and / usr / lib, but you have to adjust ldconfig when you’re done, otherwise the library won’t be found.

2)If you want to add something to the above two directories, be sure to modify / etc / ld. so. conf and then call ldconfig, otherwise you won’t find it. For example, installing a MySQL to /usr/local/mysql, MySQL has a lot of L.Ibrary is under / usr / local / MySQL / lib, so you need to add a line / usr / local / MySQL / lib under / etc / ld. so. conf, save it and ldconfig it, new librarY can only be found when the program is running.

3)If you want to put lib outside of these two directories, but you don’t want to add things in / etc / ld. so. conf (or you don’t have permission to add things). It can also be export, a global variable LD_LIBRARY_PATH, and then run the program.I will go to this directory to find library. Generally speaking, this is only a temporary solution, when there is no authority or temporary need.

4)ldconfigAll these things are related to the running time, and nothing to do with compile time. Compile or add -L to add, do not mix up;

5)In short, it’s best to ldconfig whatever changes you make to your library, or something unexpected will happen. It won’t take much time, but it will save a lot of work.

ldconfigCommand line usage is as follows:

ldconfig [-v|–verbose] [-n] [-N] [-X] [-f CONF] [-C CACHE] [-r ROOT] [-l] [-p|–print-cache]

[-c FORMAT] [–format=FORMAT] [-V] [-?|–help|–usage] path…

ldconfigThe options available are as follows:

1) -vOr — verbose: With this option, ldconfig displays the directory being scanned, the dynamic link library being searched, and the name of the connection it creates.

2)-n : With this option, ldconfig scans only directories specified on the command line, not default directories (/ lib, / usr / lib), nor directories listed in the configuration file / etc / ld. so. conf.

3)-N : This option indicates that ldconfig does not rebuild the cache file (/ etc / ld. so. cache), and if – X is not used, ldconfig updates the connection to the file as usual.

4)-X : This option indicates that ldconfig does not update the connection of the file. If the -N option is not used, the cache file is updated normally.

5)-f CONF : This option specifies that the configuration file of the dynamic link library is CONF, and the system default is /etc/ld.so.conf.

6)-C CACHE : This option specifies that the generated cache file is CACHE, and the system defaults to / etc / ld. so. cache, which stores a sorted list of sharable DLLs.

7)-r ROOT : This option changes the application’s root directory to ROOT (implemented by calling the chroot function), and when selected, the system defaults to the configuration file / etc / ld. so. conf, which actually corresponds to ROOT / etc / ld. so. conf. For example, the use of -r /When usr / zzz opens the configuration file / etc / ld. so. conf, the actual file opens is / usr / zzz / etc / ld. so. conf file, with this option, you can greatly increase the flexibility of dynamic link library management;

8)-l : Usually, when ldconfig searches for DLLs, it automatically establishes the connection of DLLs. When this item is selected, it will enter the expert mode, and the connection needs to be set manually.

9)-pOr — print – cache: This option instructs ldconfig to print out the names of all shared libraries that are stored in the current cache file;

10)-c FORMAT Or — format = FORMAT: This option is used to specify the format used for caching files, and there are three types: LD (old format), new (new format) and compat (compatible format, which is the default format);

11)-V : This option prints out the version information of ldconfig and then withdraws.

12)-? Or — help or — usage: These three options work the same way, letting ldconfig print out its help information and then exit.

Two, LDD

Function: Used to view the shared libraries needed by a program to run, often used to solve the program because of the lack of a library file can not run some problems.

lddCommand principle

1、First, LDD is not an executable program, but a shell script.

2、lddThe dependency that displays the executable module is based on setting a series of environment variables, such as LD_TRACE_LOADED_OBJECTS, LD_WARN, LD_BIND_NOW, LD_LIBRARY_VERSION, LD_VERBOSE and so on. When the LD_TRACE_LOADED_OBJECTS environment variable is not empty, any executable program displays only the dependency of the module at run time, and the program does not actually execute. It can be in shell terminal.Test:
(1) export LD_TRACE_LOADED_OBJECTS=1

(2) Then execute any program, such as LS, and see how the program runs.

3、lddThe principle of displaying dependency of executable module is realized by ld-linux.so (loader of ELF dynamic library). We know that the ld-linux.so module will work before the executable module and get control.Control, so when those environment variables are set, ld-linux.so selects dependency to display the executable module.

4、In fact, the ld-linux.so module can be executed directly, such as: / lib / ld-linux. so. 2 — list program (which is equivalent to LDD program).        

Leave a Reply

Your email address will not be published. Required fields are marked *