I'm building a program which links some shared libraries. They are contained in a lib/ directory relative to my project.
The problem I'm having is that I'd like the executable to know to search for the libraries in the relative ../lib directory. Is this possible?
I don't really want to change ld_library_path or move the files into one of the root owned standard paths.
I'm able to compile the executable and run it when the .so files are on one of the standard paths shown with strace/ldd
You can use the -rpath
from the linker (using ld as the linker).
From its manual page:
-rpath=dir
Add a directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All -rpath arguments are concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. The -rpath option is also used when locating shared objects which are needed by shared objects explicitly included in the link; see the description of the -rpath-link option. If -rpath is not used when linking an ELF executable, the contents of the environment variable "LD_RUN_PATH" will be used if it is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With