Home >Common Problem >What is the difference between dynamic library and static library
Difference: 1. The extension of static libraries is generally ".a" or ".lib"; the extension of dynamic libraries is generally ".so" or ".dll". 2. The static library will be directly integrated into the target program during compilation, and the successfully compiled executable file can run independently; the dynamic library will not be placed in the connected target program during compilation, that is, the executable file cannot run independently.
The operating environment of this tutorial: Windows 10 system, Dell G3 computer.
The most essential difference between a static library and a dynamic library is: whether the library is compiled into the target (program) .
Static (function) library
The general extension is (.a
or .lib
), this type of function Libraries usually have the extension libxxx.a
or xxx.lib
.
This type of library will be directly integrated into the target program during compilation, so the file compiled using the static function library will be larger. The biggest advantage of this type of function library is that the compilation is successful. The executable file can be run independently without requiring external requests to read the contents of the function library; however, there is obviously no advantage in terms of the ease of upgrading. If the function library is updated, it needs to be recompiled.
Dynamic function library
The extension of the dynamic function library is generally (.so
or .dll
), which Class function libraries are usually named libxxx.so
or xxx.dll
.
Unlike the static function library that is captured entirely in the program, the dynamic function library only has one "pointing" location in the program during compilation, which means that when the executable file needs to use the function library Mechanism, the program will read the function library for use; that is to say, the executable file cannot be run alone. This makes it easy to upgrade from the perspective of product function upgrade. You only need to replace the corresponding dynamic library without having to recompile the entire executable file.
In summary, it cannot be seen that:
From the perspective of productization, the published algorithm library or function library should be a dynamic library as much as possible, so that it is convenient to update and upgrade, and there is no need to To recompile the entire executable file, just replace the old dynamic library with the new version of the dynamic library.
From the perspective of function library integration, if you want to integrate all published sub-libraries (more than one) into a dynamic library to provide external interfaces, then you need to compile all sub-libraries into static libraries, so that all sub-libraries The libraries can all be compiled into the target dynamic library, and the final integrated library provides functions to the outside world.
For more related knowledge, please visit the FAQ column!
The above is the detailed content of What is the difference between dynamic library and static library. For more information, please follow other related articles on the PHP Chinese website!