Create a dynamic library:
1. Create a Win32 project in VC. For example, the project name is mytestdll. Select DLL and empty project. Then, confirm that an empty DLL project is created;
2. Add header files, source files, and Def files. The reason for using def files is that for functions in C ++, the compiler will generate different names of the original functions, using the def file can directly avoid this problem, and you do not need to define the modifiers _ declspec (dllexport) and _ declspec (dllimport.
Define the functions to be included in the DLL, for example:
Int add (int A, int B)
{
Return A + B;
}
In the def file, add the name of the function to be exported in the following format:
Then compile the project and generate the mytestdll. dll and mytestdll. Lib files.
For dynamic library display calling, you can directly use a DLL file during compilation and then loadlibrary in the program.
For implicit calls, header files, DLL files, and Lib files must be included at the same time during compilation, and preprocessing commands must be used like calling static libraries.
# Pragma comment (Lib, "libname ")
Static Library Creation is very simple. In the call project, during compilation, only the header file and Lib file are required, and the preceding pre-processing commands are also required. Note, "libname" can be included or not ". lib.
For a dynamic library, a DLL file is required during runtime, regardless of whether the project is implicitly or explicitly used during compilation. For a static library, the static library file does not need to be referenced during runtime.