Manual creation:
(1) file-> new-> project-> dynamic link library;
Name: dynamiclib
Delete the main. cpp file automatically generated by the project, and automatically add a. c File (trydll. c) to delete the main. h file to create a trydll. h file:
Trydll. c:
# Include <stdio. h> # include <string. h> # include "trydll. h "void hello () {printf (" hello \ n "); printf (" xd ");}
Trydll. h:
# Ifndef _ trydll_h00000000ded # define _ trydll_h00000000ded # include <windows. h>/* To use this exported function of dll, include this header * in your project. */# ifdef BUILD_DLL # define DLL_EXPORT _ declspec (dllexport) # else # define DLL_EXPORT _ declspec (dllimport) # endif # ifdef _ cplusplusextern "C" {# endifvoid DLL_EXPORT hello (); # ifdef _ cplusplus} # endif/_ trydll_H __
Compile the project and generate:
\ Dynamiclib \ bin \ Debug:
Test: Create a c project to call the above dynamic library:
Add the trydll. H file and add the above: file to the \ bin \ Debug \ directory under the new trydll project. Compile --> execute ......:
# Include <stdio. h> # include <stdlib. h> # include "trydll. h" int main () {hello (); printf ("Hello world! \ N "); return 0 ;}
Result:
It can be implemented simply by linking the dynamic library.
In addition, add project --> build options-> Debug-> linker settings (generate the file under the path of the dynamic library ):
However, I have not succeeded in this method.
Add a dynamic link library under codeblocks