When working on Linux, especially when compiling programs or resolving issues related to shared libraries, it's crucial to understand where the system's linker (ld
) looks for libraries by default. These search paths determine where the linker tries to find the .so
(shared object) files during compilation and runtime, and being unaware of them can lead to frustrating "library not found" errors. This tutorial explains how to print default library search directories on Linux.
Use the following command to view the default library search directories on the Linux system:
ld --verbose | grep SEARCH_DIR | tr -s ' ;' '\n'
--verbose
- dumps the full linker configuration.grep SEARCH_DIR
- filters out the lines that show library search paths.tr -s ' ;' '\n'
- cleans up the output by converting repeated spaces and semicolons into newlines, making the paths easier to read.
Example output:
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu")
SEARCH_DIR("=/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu64")
SEARCH_DIR("=/usr/local/lib64"
...
Leave a Comment
Cancel reply