在Dll1.h中:
#ifdef DLL1_API
#else
#define DLL1_API _declspec(dllimport)
#endif
DLL1_API int add(int a ,int b);
DLL1_API int subtract(int a, int b);
Dll1.cpp中:
#define DLL1_API _declspec(dllimport)
#include "Dll.h"
int add(int a,int b)
{
return a+b;
}
int subtract(int a,int b)
{
return a-b;
}
运行会出现下面问题:
C:\Users\Dll1\Dll1.cpp(5) : warning C4273: 'add' : inconsistent dll linkage. dllexport assumed.
C:\Users\Dll1\Dll1.cpp(9) : warning C4273: 'subtract' : inconsistent dll linkage. dllexport assumed.
解决办法:
Project->Setting中,C/C++->General->Preprocessor definitions中加上DLL1_API;重新编译即可