1. Version Organization
The Linux shared library version is organized into the shared library version and symbolic version:
1) Shared Library version:
The shared library uses x. y. Z to identify the shared library version. X is the primary version number, Y is the minor version number, and Z is the release version number;
When the primary version number changes, it indicates that the shared library version is incompatible, such as function signature, interface data structure, and function behavior;
When the version number changes, it indicates that the shared library version adds new features, but the existing functions and data structures are compatible;
When the release version changes, the shared library version fixes bugs or improves performance.
Therefore, if the master version of the shared library used by the application changes, the application may not be able to run. If it is only a minor version or release version upgrade, the application will not be affected.
The primary version number of the shared library that the application depends on is the same, but the minor version number is low, the application may run or cannot run, this depends on whether the application uses the added interfaces or data structures in the new version.
When running an application, if the operating system finds that the sub-version number of the shared library is low, it may adopt a policy that does not allow the program to run, but in fact, the application may not use the interfaces in higher version numbers at all.
To solve this problem, a symbolic version is introduced.
2) Symbolic version:
Symbol version, that is, each symbol has a version number. When the shared library is published, the latest version number of each symbol is identified. For example:
Vers_1.2 {
Global:
Func2;
Local:
*
}
Vers_1.1 {
Global:
Func1;
Local:
*
}
The symbolic version of func2 is 1.2, and the symbolic version of func1 is 1.1.
When an application is generated, the required version of the symbol is recorded in the application file according to the used symbol. When using a dynamic link library, if you find that the symbolic version is earlier than the version required by the application, it cannot run.
In addition, the global and local keywords are used to identify which symbols in the dynamic library are global and which are internal symbols of the shared library. Applications are not allowed to use the internal symbols of the shared library.
2. So-name
The application needs to specify the dependent shared library. Because the shared library with the same primary version number is backward compatible, you do not need to specify the full version of the shared library, but you only need to specify its primary version.
The shared library name and its main version number constitute the shared library's so-name. For example, libc. so.1.5.3, and its so-name is libc. so.1.
When libconfig is used to install a shared library, a soft link file is created for the shared library and named after so-name. For example, in the preceding example, a link file of libc. so.1 is generated, pointing to the libc. so.1.5.3 file.
3. Shared library path
Shared library files are usually placed in one of the following three paths:
/Lib: stores the most critical and basic shared libraries of the system, such as dynamic linker and C Runtime Library. These libraries are mainly used by/bin and/sbin programs, as well as the databases required for system startup;
/Usr/lib: stores the key shared libraries required for non-system running, mainly the shared library files required for development;
/Usr/local/lib: stores shared libraries irrelevant to the operating system, such as third-party runtime libraries. For example, when installing python, the shared library files required by Python are stored in/usr/local/lib/python.
4. Search for shared libraries
When an application is loaded, it searches for shared library files in the storage path of the shared library. The search order is:
1) path specified in LD_LIBRARY_PATH
2) path specified in/etc/lD. So. Cache
When ldconfig is used to install the shared library, ldconfig automatically adds the installed shared library to/etc/lD. So. cache. This file is mainly used to speed up searching shared library files.
3) default shared library directory, first/usr/lib and then/lib