RPATH
rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries. [1]
When you are compiling a program, you create object files and then link them together. You may use GNU ld(1) to link them, there are also other linkers, LLVM linker. A linker combines object files into executable. After then when you execute an already compiled ready to use executable then the dynamic linker ld.so(8) finds the libraries on the system that the executable depends on, loads them and executes the executable. ld.so(8) is a shared library usually distributed as part of C standard library, usually on linux that's glibc, but there are also other, like musl.
The -rpath
command line option in compile stage, used to create a DT_RPATH
entry in the .dynamic
section, but since DT_RPATH
was deprecated in favor of DT_RUNPATH
, modern linker versions use DT_RUNPATH
instead. This means that using -rpath
on a really old linker, you will create a dynamic section entry with .d_val = DT_RPATH
, but if your linker is up to date, you will create one with .d_val = DT_RUNPATH
instead.
The -rpath-link
option is an option which does not create any entry, but is used to supersede the DT_RUNPATH
entry present in the dynamic section of a library that is being linked. Therefore, when compiling, you should usually not need it.[2]
Administrator can modify the dynamic linker and RPATH of ELF executables using PatchELF