Ld-linux has two usage methods: indirect call and direct call.
During indirect calls, the connector embeds the ld-linux execution path into an executable file, such as an elf file, which is placed in the. interp segment.
During Direct calling, enter/lib/ld-linux-so. * [Options] [executable programs] [program parameters] in the command line.
Ld-linux searches for the shared libraries required by executable programs in the following order:
1. (Only for elf files) if the executable program contains the DT_RPATH or DT_RUNPATH segment, use the search directory specified in the two segments.
2. Use the search directory specified by the Environment Variable LD_LIBRARY_PATH
3. Use the search directory in/etc/ld. so. cache, but if the executable program adds the-z nodeflib option during connection, it is not used.
4. Use the default library directory/lib/usr/lib. If-z nodeflib is added, it is not used.
When compiling an executable program, you can install the following method to specify the directory of the shared library.
Gcc-Xlinker-rpath = DIR-o exe. c
After compilation, run readelf-d exe and you can see the following section:
0x0000000f (RPATH) Library rpath: [DIR]