In Windows, libraries can be published in the following two ways: static Link Library and dynamic link library. Static library and dynamic library (DLL ).
What is static Link Library and dynamic link library)
First, both static and dynamic libraries share code.
If you use a static Link Library, all the definitions in lib are included in the final generated EXE, whether you wish or not.
However, if a dynamic library (DLL) is used, the dynamic library does not need to be included in the final EXE file. The dynamic library can be loaded into the address space of the application at application initialization or runtime. In addition, the dynamic library can be shared by multiple applications. Many important Libraries on windows are DLL. They are shared by many applications.
Another difference between the static Link Library and the dynamic library (DLL) is that the static Link Library cannot contain other dynamic link libraries or static libraries, other dynamic or static link libraries can be included in the dynamic link library.
The differences between static and dynamic link libraries in development and usage:
The file format after static Link Library compilation is *. Lib.
Therefore, you only need the library developer to provide the. h header file and. Lib file of the library.
When developing a static library, you only need to declare the function or class in the header file, and then implement the function or class in the file.
When used, add the. h header file to the project, and then specify the. Lib file to be linked.
You can use # pragma comment (Lib, "libfilepath") to specify the static library to be linked. Or set it in project-> dependency.
For dynamic link library (DLL ):
The use of the Dynamic Link Library requires the developers of the library to provide the generated. Lib file and. dll file (the DLL is used implicitly, and the link during compilation ). Alternatively, you can only provide DLL files (using loadlibrary to explicitly use DLL files, which is loaded during runtime ).
DLL development and use require the declaration of export and import. For dynamic link libraries, it is recommended that you take a look at windows via C ++ (Windows core programming language translated in Chinese ). The book is very clear and thorough.