When the executable program to be compiled relies on a shared library, linker finds its dependent libraries in the order shown below.
The following is from GCC manual, which is recorded here as a note.
The linker uses the following search paths to locate required shared libraries.
1. Any directories specified By-rpath-link options.
2. Any directories specified By-rpath options. The
difference Between-rpath and-rpath-link is this directories specified By-rpath options are included in the Executable and used at runtime, whereas The-rpath-link option was only effective at link time. It's for the native linker only.
3. On a ELF system, if The-rpath and "Rpath-link" options were not used, search the contents of the environment Var Iable "Ld_run_path". It 's for the native linker only .
4. On SunOS, if The-rpath option is not used, search any directories specified using-l options.
5. For a native linker, the contents of the environment variable "Ld_library_path".
6. For a native ELF linker, the directories in "Dt_runpath" or "Dt_rpath" of a shared library is searched for shared Libraries needed by it. The "Dt_rpath" entries is ignored if "Dt_runpath" entries exist.
7. The default directories, Normally/lib and/usr/lib.
8. For a native linker on an ELF system, if the file/etc/ld.so.conf exists, the list of directories found in the. file.
If the required shared library is not found, the linker would issue a warning and continue with the link.
As you can see, the lookup path specified by-rpath-link is only used by linker, and-rpath specifies a lookup path that is loader as the shared library when the process starts, except for linker lookups.
"References"
1.-rpath in manual page of Gcc:man gcc and Find-rpath
======================= EOF ====================
Linker how to find a shared library when you link an executable file under the Linux notes Linux system