View dynamic library dependency instructions (ldd) under Linux system

The following introduces how to use the ldd command to check dynamic library dependencies under Linux system;

LDD is used to print or view the shared libraries required to run the program. It is often used to solve some problems where the program cannot run due to the lack of a certain library file. ldd is not an executable program, but just a shell script.

Using ldd, you can easily check the dependencies between libraries, storage paths, etc.; it is very helpful for troubleshooting the problem of not being able to link to the library;

1. Full name of ldd command

The full name of the ldd command is list dynamic dependencies (list dynamic dependencies), which is one of the commonly used commands under Linux. It can be used to display the shared libraries that an executable file or shared library (dynamic link library) depends on.

2 ldd parameter description

  • –help Get command help information;
  • –version prints the command version number;
  • -d,–data-relocs perform relocations and report any missing objects;
  • -r, --function-relocs Perform relocation of data objects and functions and report any missing objects and functions;
  • -u, --unused print unused direct dependencies;
  • -v, --verbose verbose mode, print all relevant information;

3 Simple example

ldd libEngineTask.so//查看libEngineTask.so所依赖的库

Insert image description here
It can be seen that the libEngineTask.so library needs to depend on libAIEngine.so, and the location of libAIEngine.so is ./AI_lib/libAIEngine.so, and its starting position is 0x00007f6928c7d000.

4 Check for missing dependent libraries

If the current dynamic library cannot be linked because of missing dependent libraries, you can view the missing dependent libraries through ldd. For example, in the above example, I went to the AI_lib path and manually deleted libAIEngine.so, and then executed ldd. As
Insert image description here
can be seen from the following results, the libEngineTask.so library needs to depend on libAIEngine.so, but libAIEngine.so cannot be found. , to facilitate troubleshooting.

5. Detailed introduction of ldd command

1. ldd is an important command in Linux, used to print dynamic link library information on which executable files or shared libraries depend. The functions and usage of the ldd instruction are introduced in detail below.

Command format:
ldd [options] <executable file or shared library>

2. Function description:
The ldd command displays a list of dynamic link libraries that an executable file or shared library depends on. It recursively checks all libraries the file depends on and displays their paths. Through the ldd command, you can learn about the library files required for a program to run, as well as information such as whether these library files exist and whether their versions match.

3. Commonly used options:
-v, --verbose: Display detailed debugging information, including version number, loading method, etc.
-u, --unused: Only unused directly dependent libraries are displayed.
-r, --function-relocs: Display function relocation information in associated libraries.
-d, --data-relocs: Display data relocation information in the associated library.
–help: Display help information.
–version: Display version information.

4. Usage examples:
(1) Check the libraries that the executable file depends on:
ldd /path/to/executable

(2) Check the dependencies of the shared library:
ldd /path/to/shared_library.so

(3) Display detailed dependent library information:
ldd -v /path/to/executable

(4) Only display unused directly dependent libraries:
ldd -u /path/to/executable

(5) Display relocation information of functions and data:
ldd -r /path/to/executable

5. Output interpretation:
For each dependent library, ldd will display its path and mark its status in the following format:
=> File path: Find and link normally.
=> not found: The library file was not found.
=> version mismatch: version mismatch.
=> incompatible: Incompatible with executables or other libraries.
=> symbol not found: A symbol cannot be found.

Additionally, the ldd command can also display other libraries required by the library. By observing the output results, you can understand and solve dynamic link library-related issues in a timely manner during the development and debugging process.

Using the ldd command can help developers, system administrators, etc. quickly understand whether the library files required for program running exist and whether the versions match, thereby troubleshooting library dependency issues. During the debugging and deployment process, ldd is a very useful tool that can improve development efficiency and reduce the possibility of errors.

Guess you like

Origin blog.csdn.net/AnChenliang_1002/article/details/131363182