Extern "C" DLL: Debugging is OK, Release throws Error C2059

I have a DLL that I created as a C ++ Win32 application. To prevent a name change in my DLL, I used the EXPORT definition defined below:

#ifndef EXPORT #define EXPORT extern "C" __declspec(dllexport) #endif EXPORT int _stdcall SteadyFor(double Par[], double Inlet[], double Outlet[]); 

To get this code for compilation, I had to go into the Properties project and set the C / C ++ Calling Convention to __ stdcall (/ Gz) and set Compile As to Compile As C ++ Code (/ TP) .

This worked in debug mode, but Release mode throws error C2059: syntax error: 'string' to all my EXPORT functions, even if I configured the release mode settings in the same way as Debug settings.

How do I get release mode for compilation?

Respectfully,
~ Joe
(Development for Visual Studio 2008 Professional)

EDIT:
A lot of comments about my #define, which seems to cause no problems.

To eliminate the confusion, my header file was rewritten as follows:

 #ifndef coilmodel_h #define coilmodel_h extern "C" __declspec(dllexport) int _stdcall steadyFor(double Par[], double Inlet[], double Outlet[], char* FileIn, char* FileOut); #endif 

That's all.

Error:
Description of error C2059: syntax error: 'string'
File coilmodel.h
Line 4

Again, this error only appears in Release mode, and not in Debug mode.
A project is a C ++ Win32 DLL application.

+4
source share
4 answers

If your source file has a .c extension, the compiler you use will compile it as C (not C ++) and create this error in extern "C" . If so, you need to use the /TP switch, as you already noted, or rename the file to .cpp . Another solution is to set #ifdefs around extern:

 #ifdef __cplusplus extern "C" #endif 
+6
source

I would suggest that EXPORT is defined as something else in releases. Since you have #ifndef around your definition, it will not do anything if it is already defined, then you will get something else (maybe a string?) Inserted at the beginning of your function declarations.

So try something like this:

 #ifdef EXPORT #error EXPORT already defined! #else #define EXPORT extern "C" __declspec(dllexport) #endif 
+2
source

Formation of Compile As for compilation in the form of code in C ++ (/ TP) - you installed it in all configurations of the assembly - debug / release x 32 / x64, etc. I do not use this option, it is much easier to name the file accordingly for the compiler to automatically select.

You only need the "C" extern "C" if the C ++ file disables the name change.

I prefer to organize a common public header using this format, so you can include it in C / C ++ both internally and externally.

 #ifdef __cplusplus # define NOMANGLE extern "C" #else # define NOMANGLE #endif #ifdef EXPORT_BUILD # define EXPORT NOMANGLE __declspec(dllexport) #else # define EXPORT NOMANGLE __declspec(dllimport) #endif 
+1
source

Impossible, but make sure dllexport or _stdcall is not #defined ...

0
source

Source: https://habr.com/ru/post/1313534/


All Articles