Linker how to find a shared library when you link an executable file under the Linux notes Linux system

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.