我有一个我作为C++ Win32应用程序创建的DLL.为了防止我的DLL中的名称损坏,我使用了以下定义的EXPORT定义:
#ifndef EXPORT
#define EXPORT extern "C" __declspec(dllexport)
#endif
EXPORT int _stdcall SteadyFor(double Par[], double Inlet[], double Outlet[]);
Run Code Online (Sandbox Code Playgroud)
为了编译这个代码,我不得不进入项目的属性并将C/C++设置Calling Convention为__stdcall(/ Gz)并设置Compile As为Compile as C++ Code(/ TP).
这在调试模式下工作,但释放模式正在抛出error C2059: syntax error: 'string'我的所有EXPORT函数 - 即使我已将Release模式设置配置为与Debug设置相同.
如何编译发布模式?
问候,
~Joe
(在Visual Studio 2008 Professional下开发)
编辑:
很多关于我的#define的评论,似乎没有引起任何问题.
为了消除这种混淆,我的头文件已被重写如下:
#ifndef coilmodel_h
#define coilmodel_h
extern "C" __declspec(dllexport) int _stdcall steadyFor(double Par[], double Inlet[], double Outlet[], char* FileIn, char* FileOut);
#endif
Run Code Online (Sandbox Code Playgroud)
这就是全部.
错误是:
描述 error C2059: syntax error: 'string'
文件 coilmodel.h
行 4
同样,此错误仅出现在"释放"模式下,而不是"调试"模式.
Project是一个C++ Win32 DLL应用程序.
如果您的源文件有.c扩展名,那么您使用的编译器会将其编译为C(而不是C++)并在该文件上产生该错误extern "C".如果是这种情况,那么您需要使用/TP已经记下的开关或将文件重命名为.cpp.另一个解决方案是将#ifdefs放在extern周围:
#ifdef __cplusplus
extern "C"
#endif
Run Code Online (Sandbox Code Playgroud)