Understanding rpath, runpath, and LD_LIBRARY_PATH
Understanding rpath, runpath, and LD_LIBRARY_PATH
- rpath (Runtime Path):
rpath
is a flag within an executable file used to specify the search path for shared libraries at runtime.- When a program runs, the system searches for shared libraries based on the
rpath
setting. If the corresponding shared libraries are found, the program can run successfully. rpath
is set during compilation or linking of the program and can be specified using therpath
option or in aMakefile
.
- runpath (Dynamic Run-time Linking):
runpath
is an alternative mechanism torpath
used to specify the search path for shared libraries at runtime.- Unlike
rpath
,runpath
can be modified dynamically at runtime, meaning its value can be changed as needed without recompiling or relinking the program. runpath
settings can also be specified during compilation or linking, typically using therunpath
option or corresponding linker options.
- LD_LIBRARY_PATH:
LD_LIBRARY_PATH
is an environment variable used to specify the search path for shared libraries.- When a program runs, the system searches for shared libraries in the paths specified in the
LD_LIBRARY_PATH
variable. - Unlike
rpath
andrunpath
,LD_LIBRARY_PATH
is a global environment variable that affects all running programs in the system. Therefore, it should be used with caution. LD_LIBRARY_PATH
can be set in the command line, for example:export LD_LIBRARY_PATH=/path/to/lib
.
In summary, these mechanisms address the issue of how shared libraries are located and loaded during program runtime. rpath
and runpath
are primarily specified by program developers during compilation or linking, whereas LD_LIBRARY_PATH
is a global environment variable that can be set by system administrators or users. rpath
and runpath
have higher search priority and are generally considered more reliable, while LD_LIBRARY_PATH
is a global configuration option that can potentially impact all programs on the system and should be used with caution.