Difference and use of static library and dynamic library

basic concept

Function library:
A function library is a collection of functions with certain functions established by the system. The library stores the name of the function and the corresponding object code, as well as the relocation information required during the linking process . Users can also build their own user function library according to their own needs.
 
Library Functions:
Functions stored in function libraries. Library functions have clear functions, entry call parameters and return values.
 

static library

The suffix is ​​.lib file under windows and .a file under Linux.

When compiling, you need to include the interface header file and static library, and the code will be compiled directly into the executable file. The advantage is that the runtime does not depend on static library files. However, when the compiled file is large, and the static library method is changed, all projects that depend on this file need to be recompiled

dynamic library

The dynamic library contains files with the suffix .lib and .dll under Windows. The .lib file is an import library, which does not contain code, but provides information for the linker, including the relocation table to be used when establishing a dynamic link in the .exe file.

The import library is used for program development, and the dynamic library is used for program runtime.

Dynamic libraries are divided into explicit calls and implicit calls:

Implicit call

When compiling, include import libraries and interface header files. At runtime, the dynamic library needs to be included, otherwise an error will be reported. Implicit call coding is simple, but all dynamic libraries will be loaded into memory at startup, which will waste resources.

explicit call

When compiling, no import library and interface files are required. At runtime, the dynamic library is loaded only when needed, so it is more flexible.

Need to use in Linux

dlopen(), dlsym(), dlclose() three functions

Need to use under windows

LoadLibrary, GetProcAddress, FreeLibrary three functions load dynamic library

refer to:

https://www.cnblogs.com/westsoft/p/5936092.html

https://blog.csdn.net/star_xiong/article/details/17301191

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325681044&siteId=291194637