Created using VS2019 C ++ dynamic link library

Static library: functions and data is compiled into a binary file, usually with extension .lib, in the case of static library, when compiled and linked executable file, the linker functions and data copied from the library and take them other modules of the application to create the final executable file together.

DLL: often provide two files, one is the introduction of a DLL and library, import library contains symbolic names of functions and variables to be exported by the DLL, DLL contains the actual functions and data. When compiled and linked executable file, just link the import library, a DLL function code and data is not copied into the executable file, at runtime, go load the DLL, visit the DLL export functions.

The benefits of using the DLL: 1. You can use a variety of programming language; 2 enhancements to the product; 3 to provide secondary development platform; 4 simplify project management, and development; 5 saves disk space and memory.... , multiple programs use the same resources; 6. facilitate the sharing of resources; 7 helps to localize the application.

DLL is loaded in two ways:

Implicit links:

The new procedure ① DLL, in which two new addition and subtraction functions;

 

 After compiling open the DEBUG file in the project folder, you can see the generated dll file;

 

Open command Cmd bed open, this switch the path (the file path replication, i.e., the right paste command window), the input dumpbin -exports Dll1.dll, can see the information derived from the DLL, if the command does not recognize dumpbin necessary to add environment variables (my installation path is: C: \ Program Files (x86) \ Microsoft Visual Studio \ 2019 \ Professional \ VC \ Tools \ MSVC \ 14.23.28105 \ bin \ Hostx64 \ x64)

 

 

 We return to the code, increase _declspec (dllexport) in front of each function name, and then re-compiled, the resulting file found more than a Dll1.lib file, which is said earlier introduction of libraries;

 

 Then re-run cmd command, you can see the information we export function, because c ++ with overloaded function, the function name will be identified by a bunch of symbols internal compiler displays.

 

 Test results: Re-new C ++ console program, call the Add and Sub functions, additional library dependencies added Dll1.lib in the property, and copy the file to the directory (Dll1.lib and Dll1.dll);

 

 The same test procedure can be used to view dumpbin input file information

 

Guess you like

Origin www.cnblogs.com/asce/p/11621588.html