YouTip LogoYouTip

Linux Comm Ldd

[![Image 1: Linux Command Encyclopaedia](#) Linux Command Encyclopaedia](#)\n\n* * *\n\nldd (List Dynamic Dependencies) is a very useful command-line tool in Linux systems, used to display the dynamic shared libraries that a program or shared library depends on. When you run a program on Linux, the system needs to load various shared libraries (.so files) that the program depends on. ldd is the tool used to view these dependency relationships.\n\n* * *\n\n## Basic Syntax of ldd Command\n\nldd executable or shared library\n\n### Commonly Used Option Parameters Description\n\n| Option | Description |\n| --- | --- |\n| -v | Display detailed version information |\n| -u | Display unused direct dependencies |\n| -d | Perform relocations and report missing functions |\n| -r | Perform relocations and report missing functions and data |\n| --help | Display help information |\n\n* * *\n\n## How ldd Command Works\n\nldd is actually a script that runs the target program by setting special environment variables, causing the program to display its dependency library information instead of executing normally. Specifically:\n\n1. For ELF format executable files, ldd parses their dynamic segment\n2. Check DT_NEEDED entries to determine required shared libraries\n3. Search for these library files in system library paths\n4. Display the full path and memory address mapping of each library\n\n* * *\n\n## Usage Examples\n\n### Example 1: View Dependencies of a Simple Program\n\nldd /bin/ls\n\nTypical output:\n\nlinux-vdso.so.1 (0x00007ffd5a3f0000) libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f8e4a3b0000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8e4a1c0000) libpcre2-8.so.0 => /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f8e4a130000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8e4a120000)/lib64/ld-linux-x86-64.so.2 (0x00007f8e4a400000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8e4a100000)\n\n### Example 2: Check Unused Direct Dependencies\n\nldd -u /usr/bin/python3\n\n### Example 3: View Dependencies in Verbose Mode\n\nldd -v /usr/bin/gcc\n\n* * *\n\n## Practical Application Scenarios\n\n### Scenario 1: Solving "library not found" Errors\n\nWhen a program fails to run due to missing libraries, ldd can help quickly locate the problem:\n\nldd ./my_program | grep "not found"\n\n### Scenario 2: Check for Library Version Conflicts\n\nldd -r ./my_program\n\n### Scenario 3: Verify Library Paths are Correct\n\nldd /path/to/your/executable | awk '{print $3}' | xargs ls -la\n\n* * *\n\n## Precautions and Common Issues\n\n1. **Security Warning**: Do not use ldd on untrusted executables, as it actually attempts to execute parts of the program's code\n\n * Alternative: `objdump -p /path/to/program | grep NEEDED`\n\n2. **Statically Linked Programs**: For fully statically linked programs, ldd will display "not a dynamic executable"\n\n3. **Cross-compilation Environment**: In cross-compilation environments, you need to use the ldd tool for the corresponding platform\n\n4. **Common Errors**:\n\n * `ldd: ./program: No such file or directory` β†’ May be missing the interpreter or the program itself doesn't exist\n * `ldd: exited with unknown exit code` β†’ The program may have crashed during execution\n\n* * *\n\n## Advanced Tips\n\n### 1. Combine with readelf to View More Detailed Dependency Information\n\nreadelf -d /path/to/program | grep NEEDED\n\n### 2. Use LD_TRACE_LOADED_OBJECTS Environment Variable\n\nLD_TRACE_LOADED_OBJECTS=1 /path/to/program\n\n### 3. Check Library Dependency Tree\n\nldd /path/to/library.so | awk '{print $3}' | xargs ldd\n\n* * *\n\n## Summary\n\nldd is an indispensable tool in Linux system management and program debugging. It can:\n\n* Quickly display the dynamic library dependencies of a program\n* Help solve library missing or version conflict issues\n* Verify whether the program running environment is complete\n* Assist in software packaging and deployment\n\nMastering the use of the ldd command can greatly improve your efficiency in solving dependency problems in Linux environments.\n\n* * Linux Command Encyclopaedia](#)
← Linux Comm PerfLinux Comm Gdb β†’