LD_LIBRARY_PATH and/etc/lD. So. cache file

Source: Internet
Author: User

Reprinted link http://blog.chinaunix.net/uid-25304914-id-3046279.html

Part of the library executable program

Dynamic Link correlation LDD

Http://hi.baidu.com/%C4%FE%BE%B2%B5%C4%B7%B1%BB%AA/blog/item/deac821366ba9565cb80c441.html

LD_LIBRARY_PATH:

This environment variable is mainly used to specify other paths except the default path when searching for a shared library (dynamic link library. (This path is located before the default path)

The default path is/usr/lib, And/lib.

In addition to setting this variable/Etc/lD. So. conf fileAnd then execute ldconfig to build the dictionary:/etc/lD. So. Cache
.

The paths set in/etc/lD. So. conf and LD_LIBRARY_PATH are the trusted library paths except/usr/lib and/lib.

LD. So and ld-linux.so this library is responsible for loading the dynamic library that needs to be used.

LD. SoThe program processes the. Out binary program. This format was used a long time ago;Ld-linux.so *People have been using this format for processing elf until now. In addition, the two are the same, and the same support files and programs are used, suchLDD (1),Ldconfig (8)And/etc/lD. So. conf.

 

Find the shared libraries required by the program in the following order:

1. (Only for ELF) if the dt_runpath attribute in the binary program does not exist and the dt_rpath dynamic segment attribute exists, the directory specified in dt_rpath is used. The use of dt_rpath has been deprecated.

2. Use Environment VariablesLD_LIBRARY_PATH. Unless the executable program isSet-user-ID or set-group-IDBinary program. In this case, it is ignored.

3. (Only for ELF) if the dt_runpath dynamic segment attribute in the binary program exists, use the directory specified in it.

4. Search from the cache file/etc/lD. So. cache. This file contains the list of compiled candidate libraries found in the library path. However, when a binary program is used-Z nodeflibWhen the linker option is linked, the libraries in the default library path will be ignored.

5. In the default path/lib, then/usr/lib. If the binary program uses-Z nodeflibThis step is skipped.

 

Http://blog.163.com/jinyu345/blog/static/677789220118910137891/

/Etc/lD. So. conf;/etc/lD. So. cache file

There are two different types of Linux executable programs on Linux.

The first type is static linked executable programs. Static executable programs include all the functions required for execution-in other words, they are "complete ". For this reason, static executable programs can run without relying on any external library.

The second type is dynamic linked executable programs.

  Comparison between static and dynamic executable programs

We can use the LDD command to determine whether a specific executable program is statically linked:
# LDD/sbin/SLN
Not a dynamic executable
"Not a dynamic executable" is LDD, indicating that SLN is a static link. Now, let's compare the size of the SLN and its non-static similar ln:
# Ls-L/bin/ln/sbin/SLN
-Rwxr-XR-x 1 Root 23000 Jan 14 00:36/bin/ln
-Rwxr-XR-x 1 Root 381072 Jan 14 00:31/sbin/SLN
As you can see, the SLN is more than 10 times the ln size. Ln is much smaller than SLN because it is a dynamic executable program. Dynamic executable programs are incomplete programs that rely on external shared libraries to provide the many functions required for running.

  Dynamic Link correlation

To view the list of all the shared libraries on which ln depends, run the LDD command:
# LDD/bin/ln
Libc. so.6 =>/lib/libc. so.6 (0x40021000)
/Lib/ld-linux.so.2 =>/lib/ld-linux.so.2 (0x40000000)

As you can see, ln depends on the external shared library libc. so.6 and ld-linux.so.2. Generally, programs with dynamic links are much smaller than their equivalent programs with static links. However, programs with static links can play a role in some low-level maintenance tasks. For example, SLN is an excellent tool for modifying the symbolic links of different libraries in/lib. However, you usually find that almost all executable programs on Linux systems are variants of some kind of dynamic links.

 Dynamic Loader

If a dynamic executable program does not contain all the functions required for running, which part of Linux is responsible for loading these programs together with all necessary shared libraries so that they can be correctly executed? The answer is dynamic loader, which is actually the ld-linux.so.2 library that you see in the LDD list of LN as a shared library relevance. The dynamic loader is responsible for loading the shared libraries required by the dynamic link executable program. Now, let's take a quick look at how the dynamic loader finds the appropriate shared library on the system.

LD. So. conf

The dynamic loader relies on two files-/etc/lD. So. conf and/etc/lD. So. cache to find the shared library. If you perform CAT operations on the/etc/lD. So. conf file, you may see a list similar to the following:

$ CAT/etc/lD. So. conf

/Usr/x11r6/lib

/Usr/lib/GCC-lib/i686-pc-linux-gnu/2.95.3

/Usr/lib/Mozilla

// Usr/lib/qt-x11-2.3.1/lib

/Usr/local/lib

The LD. So. conf file contains a list of all directories (except/lib and/usr/lib, which are automatically included in the list), and the dynamic loader searches for shared libraries.

LD. So. Cache

But before the dynamic loader can "see", it must be converted to the lD. So. cache file. You can do this by running the ldconfig command:

# Ldconfig

When the ldconfig operation ends, you will have the latest/etc/lD. So. cache file, which reflects your changes to/etc/lD. So. conf. From this moment on, the dynamic loader will view all the new directories you specified in/etc/lD. So. conf when searching for shared libraries.
  

  Ldconfig skills
  

To view all the shared libraries that ldconfig can "see", enter:
  

# Ldconfig-p | less

Another convenient technique can be used to configure the shared library path. Sometimes you want to tell the dynamic loader to try to use the shared library in a specific directory before trying any/etc/lD. So. conf path. This is convenient if the older application you are running cannot work with the currently installed library version.

LD_LIBRARY_PATH

To instruct the dynamic loader to first check a directory, set the LD_LIBRARY_PATH variable to the directory you want to search. Multiple paths are separated by colons. For example:

# Export LD_LIBRARY_PATH = "/usr/lib/old:/opt/lib"

After LD_LIBRARY_PATH is exported, if possible, all executable programs started from the current shell will use the libraries in/usr/lib/old or/opt/lib, if some shared library relevance requirements still cannot be met, it will be switched back to/etc/lD. so. the specified library in Conf.

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.