创建动态链接库
程序代码:
#ifdef _LIB #ifndef HELLOWORLD_API #define HELLOWORLD_API extern #define HELLOWORLDLIB_API extern #pragma message("LIB") #endif #endif #ifdef _USRDLL #ifdef HELLOWORLDLIBDLL_EXPORTS #define HELLOWORLD_API extern __declspec(dllexport) #define HELLOWORLDLIB_API extern __declspec(dllexport) #pragma message("Create HELLOWORLD dllexport") #else #define HELLOWORLD_API extern __declspec(dllimport) #define HELLOWORLDLIB_API extern __declspec(dllimport) #pragma message("Using HELLOWORLD dllexport") #endif #endif #ifdef __cplusplus extern "C" { #endif HELLOWORLD_API void print(); HELLOWORLD_API int add(int a, int b); #ifdef __cplusplus } #endif
程序代码:
#include <stdio.h> #include "HelloWorldDll.h" int main() { print(); int c = add(1, 2); return 0; } /* void print() { printf("hello world"); } int add(int a, int b) { return a+b; } */