Is there a way to add the relative path of the library to the executable to avoid setting LD_LIBRARY_PATH

I am creating a program that links some common libraries. They are contained in the lib / directory of my project.

The problem I'm running into is that I would like the executable to know to look for libraries in the relative./lib directory. Is it possible?

I really don't want to modify ld_library_path or move files to one of the standard root paths.

I can compile the executable and run it when the .so files are in one of the standard paths shown with strace / ldd

+3


source to share


1 answer


You can use -rpath

from the linker (using ld as the linker).

From the man page:



-rpath = directory

Add the 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 find shared objects at runtime. The -rpath parameter is also used to find shared objects, which are required for shared objects that are explicitly referenced; see the description of the -rpath-link option. If -rpath is not used when linking the ELF executable, the contents of the "LD_RUN_PATH" environment variable will be used if specified.

+6


source







All Articles