Use visual studio 2013 to develop static and dynamic libraries

First develop the static library

Create a new Win32 project, named lib_demo

 

 

 Add a header file testlib.h

Add a source file testlib.cpp

 

 Select the project, right click, and click Generate

 

 It can be seen that the .lib file has been generated under the directory D:\visual studio 2013\Projects\lib_demo\Debug, which is the static library

 Test the static library below

 

 

 Select the project, right-click to regenerate, and an error will be reported

 

 

 At this time we need to add the library directory, select the project test, right-click-"Properties-"Linker-"General-"Additional library directory

Use a relative directory here

 Select the project test again, right click - "Regenerate, and the executable file can be generated. Then, select the project test, right-click-"debug-"start a new instance, and you can run it

 

Create a dynamic library below

 

 

 

 

 

 

 

 Then, you can right click and run the file

The dynamic library is tested

Another way to specify the export function is to use Source.def to specify the function to be exported , so that there is no need to add __delspec(dllexport) modification in front of the function, comment out the original export function in the project, and only keep two function, lines 16, 17.

Then add Source.def  in the project dll_demo

 

 

 

 Then, you can re-run the project test

Guess you like

Origin blog.csdn.net/yanzhenxi/article/details/127328207