Dynamic library and static library
Many repeated or frequently used parts are often encountered during programming. These parts are encapsulated into function libraries for ease of use and maintenance. Function libraries can be divided into static and dynamic libraries.
Static Library
Writing is simple. Just like writing common source files, you can set the configuration type in project properties to a static library, but you must save the Library to the directory of the calling file, each time the library file is modified, it is generated and saved to the directory of the calling file.
1. Project Settings: set the project to static library type and select project properties
Set the project configuration type to static library
2. Code Writing: Compile the library file code, which is the same as writing the source file.
Library file source code
3. Generate a library file: generate the source file into a library file (*. lib). The generated library file can be seen in the Debug folder in the solution folder.
Generate library files
Open"Solution"Folder (solution folder, not project folder)
View the generated static library file in Resource Manager
4. import and use the library file:
Copy the static library file to the called project folder
Introduce the static library file and call the method in the file
5. Run the test
Call successful
PS: the source code of the database must be modified in order. Repeat steps 2 ~ Step 4
Dynamic library
It is relatively complex to write and call source code. Before defining a function, add "_ declspec (dllexport)". Set the configuration type in the project attribute to a dynamic library, you do not need to save the database to the directory of the calling file. Therefore, you do not need to save each modification to the calling file directory.
1. Project Settings: set the project to a dynamic library type
Select Project Properties
Set the project configuration type to dynamic library
2. Code Writing: Compile the library file code, which is the same as writing the source file, but add "_ declspec (dllexport)" before function definition )"
Library file source code
3. Generate a library file: generate the source file into a library file (*. dll). The generated library file can be seen in the Debug folder in the solution folder.
Generate library files
Open"Solution"Folder (solution folder, not project folder)
View the generated static library file in Resource Manager
4. import and use the library file:
Introduce the dynamic library file and call the method in the file
5. Run the test:
Call successful
It can be seen that the dynamic library is suitable for sharing. Multiple projects can share one dynamic library to reduce the program volume. Static libraries are suitable for private and projects do not share static libraries.