Print a list of shared libraries that a program or library file depends on
ldd command is used to print the list of shared libraries that a program or library file depends on.
ldd(options)(parameters)
--version: print instruction version number;
-v: Detailed information mode, prints all relevant information;
-u: Print unused direct dependencies;
-d: Perform relocation and report any missing objects;
-r: Perform relocation of data objects and functions and report any missing objects and functions;
--help: Display help information.
File: Specify an executable program or library.
First of all, ldd is not an executable program, but just a shell script.
ldd can display the dependency of executable modules by setting a series of environment variables, as follows: LD_TRACE_LOADED_OBJECTS, LD_WARN, LD_BIND_NOW, LD_LIBRARY_VERSION, LD_VERBOSE
, etc. When the LD_TRACE_LOADED_OBJECTS
environment variable is not empty, when any executable program is run, it will only display the dependency of the module, and the program will not actually execute. Otherwise, you can test it in the shell terminal, as follows:
export LD_TRACE_LOADED_OBJECTS=1
Then execute any program, such as ls, etc., to see the running results of the program.
ldd displays the working principle of dependency of executable modules. Its essence is realized through ld-linux.so (the loader of elf dynamic library). We know that the ld-linux.so module will work before the executable module program and gain control, so when the above environment variables are set, ld-linux.so chooses to display the dependency of the executable module.
In fact, you can directly execute the ld-linux.so module, such as: /lib/ld-linux.so.2 --list program
(this is equivalent to ldd program)