On the usage of ldconfig and ldd in Linux

  • 2020-05-14 05:51:32
  • OfStack

ldd views program dependencies libraries

ldd

Function: it is used to view the Shared library needed for the program to run. It is often used to solve some problems that the program cannot run due to the lack of a library file.

Example: view the libraries on which the test program runs:

/opt/app/todeav1/test$ldd test
libstdc++.so.6 = > /usr/lib64/libstdc++.so.6 (0x00000039a7e00000)
libm.so.6 = > /lib64/libm.so.6 (0x0000003996400000)
libgcc_s.so.1 = > /lib64/libgcc_s.so.1 (0x00000039a5600000)
libc.so.6 = > /lib64/libc.so.6 (0x0000003995800000)
/lib64/ld-linux-x86-64.so.2 (0x0000003995400000)

The & # 8226; Column 1: what libraries does the program depend on

The & # 8226; Column 2: the library provided by the system corresponding to the library required by the program

The & # 8226; Column 3: the starting address of the library load

From the above information, we can get the following information:

1. By comparing column 1 and column 2, we can analyze whether the library that the program needs to rely on matches what the system actually provides

2. By looking at column 3, we can see where the symbols in the current library start in the address space of the corresponding process

If a dependent library cannot be found, this command can quickly locate the problem.

annotations

How it works: ldd is not an executable, but an shell script. ldd shows the working principle of dependency of the executable module, which is realized by ld-linux.so (the loader of elf dynamic library). The ld-linux.so module works before the executable module program and gains control, so when those environment variables are set, ld-linux.so selects dependency, which displays the executable module.

--------------------------------------------------------------

ldconfig is a dynamic link library management command. In order for the dynamic link library to be Shared by the system, it is necessary to run the management command of dynamic link library and ldconfig. ldconfig command USES, primarily in the default search directory (/ lib and/usr/lib) and dynamic library configuration file/etc/ld so. conf listed in the directory, search can be Shared out the dynamic link library (format such as former introduction, lib *. so *), and create dynamic loader (ld. so) needed for the connection and the cache file. By default cache files / etc ld. so. cache, this file has been sorted dynamic link library name list.

linux Shared library mechanism under the adopted similar to cache mechanism, the library information stored in the/etc/ld so. cache inside.

When the program connects, it first looks in this file and then goes to the path ld.so.conf to find the details.

Is that why you changed ld.so.conf to rerun 1 ldconfig

Add 1, ldconfig is inside /sbin.

A few caveats about ldconfig

1. To/lib and/usr/lib add contents, is don't need to modify/etc/ld so. conf, but after ldconfig asked 1, otherwise the library will find

2. Want to two directories to plus the above things, 1 need to modify/etc/ld so. conf, then call ldconfig, or you will find

Such as 1 mysql installed to/usr local/mysql, mysql have 1 big library in/usr local/mysql/lib below, this is where the in/etc/ld so. conf below 1 row/usr/local/mysql/lib, save after ldconfig1, The new library can only be found when the program is running.

3. If you want to put lib outside these two directories, but don't want to in the/etc/ld so. Add something conf (or there is no permission to add). That's fine, export1 global variable LD_LIBRARY_PATH, and then when you run your application, you go to this directory and you look for library. 1 this is generally a temporary solution that can be used without permission or temporary need.

4. ldconfig does all of these things when you run the program, not at 1 point at compile time. I'm still going to add -L when I compile it, so don't confuse it.

5. In a word, no matter what changes have been made to library, it is better to make ldconfig1, otherwise there will be some unexpected results. It won't take much time, but it will save a lot of work.


Related articles: