Linux shared library

xiaoxiao2021-03-17  178

Quote from: http://www.cublog.cn/opera/showart.php? Blogid = 4512 & id = 73436

Shared libraries Introduction There are two types of different LINUX executables on the shared library Linux system. The first category is a rectified program of a static link. Static executables contain all functions required - in other words, they are "complete". For this reason, the static executor can run without relying on any external library. The second category is an executable program that dynamically link. Static Executable Program and Dynamic Executable Compare We can use the LDD command to determine if a particular executable is static link: # ldd / sbin / sln NOT A DYNAMIC EXECUTABLE "NOT A DYNAMIC EXECUTABLE" is LDD Description SLN is A way of static links. Now, let us compare SLN and its non-static similar LN size: # ls -l / bin / ln / sbin / sln-rwxr-xr-x 1 root root 23000 Jan 14 00:36 / bin / ln-rwxr-xr- x 1 root root 381072 JAN 14 00:31 / sbin / sln As you see, SLN has a size of more than ten times. LN is much smaller than SLN because it is a dynamic executable program. The dynamic executor is an incomplete program that rely on an external shared library to provide many functions required to run.

Dynamic link correlation

To view a list of all shared libraries dependent on LN, you can use 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)

If you see, LN relies on external shared libraries libc.so.6 and ld-linux.so.2. Usually, the dynamic linking program is much smaller than the equivalent programs of its static link. However, the static link program can play a role in some low-level maintenance tasks. For example, SLN is an excellent tool that modifies a different library symbol link located in / lib. But usually you will find that the executable on almost all Linux systems is a variant of a dynamic link. Dynamic loading

Then, if the dynamic executor does not contain all the functions required to run, the Linux is responsible for loading these programs and all necessary shared libraries so that they can execute correctly? The answer is a dynamic loader, which is actually the LD-Linux.so.2 library listed as shared library relevance in LDD in LN. The dynamic loader is responsible for loading the shared libraries required to run the dynamic link. Now let's quickly check how the dynamic loader finds the appropriate shared library on the system.

ld.so.conf

Dynamic loaders find shared libraries to rely on two files - /etc/ld.so.conf and /etc/ld.so.cache. If you perform Cat 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 all directories (except / lib and / usr / lib), which will be automatically included therein, and the dynamic loader will find shared libraries.

ld.so.cache

However, before the dynamic loader can "see" this information, 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 made to /etc/ld.so.conf. From this moment, the dynamic loader views all the new directory you specified in /etc/ld.so.conf when looking for shared libraries.

LDConfig skills

To view all shared libraries that LDConfig can "see", enter: # ldconfig -p | less

There is another convenient skill to configure the shared library path. Sometimes you want to tell the dynamic loader attempt to use the shared libraries in a specific directory before trying any /etc/ld.so.conf path. This will be more convenient to work with the older app you run with the currently installed library version.

LD_LIBRARY_PATH To indicate that the dynamic loader first checks a directory, set the ld_library_path variable to the directory you want to search. The multiple paths are separated by commas; for example: # export ld_library_path = "/ usr / lib / old: / opt / lib" After exporting LD_Library_path, if possible, all executables starting from the current shell will be used / usr The library in / lib / old or / opt / lib, if you still can't meet some shared library relevance requirements, turn back to the library specified in /etc/ld.so.conf.

转载请注明原文地址:https://www.9cbs.com/read-129515.html

New Post(0)