我已经创建了一个DLL文件,在头文件中我看到了:
#ifdef WIN32DLL_EXPORTS
我不明白它是什么意思以及我们在何处/如何设置WIN32DLL_EXPORTS
。
如果我使用:
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif
WIN32DLL_API int testSum(void);
testSum
被视为__declspec(dllimport)
。所以我认为我的项目没有设置为WIN32DLL_EXPORTS
?我怎么能改变这个?
答案 0 :(得分:11)
在您引用的行的正上方有一个注释块。阅读它。
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the WIN32DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// WIN32DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif
答案 1 :(得分:3)
你可以:
WIN32DLL_EXPORTS
定义中定义Properties > Configuration Properties > C/C++ > Preprocessor > Preprocessor
。WIN32DLL_EXPORTS
语句定义#define
。