tags:

views:

76

answers:

4

I've got a DLL that I've created as a C++ Win32 application. To prevent name mangling in my DLL, I have 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 to compile, I had to go into the project's Properties 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 is throwing error C2059: syntax error: 'string' on all of my EXPORT functions - even though I have configured the Release mode settings to be the same as the Debug settings.

How do I get Release Mode to compile?

Regards,
~Joe
(Developing under Visual Studio 2008 Professional)

EDIT:
A lot of comments about my #define, which does not appear to be causing any problems.

To eliminate the confusion, my header file has been 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 is all of it.

The error is:
Description error C2059: syntax error: 'string'
File coilmodel.h
Line 4

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

+2  A: 

I would guess EXPORT is defined as something else in Release builds. Since you've got an #ifndef around your definition, that won't do anything if it is already defined, then you get something else (maybe a string?) pasted at the beginning of your function declarations.

So maybe try something like this:

#ifdef EXPORT
    #error EXPORT already defined!
#else
    #define EXPORT extern "C" __declspec(dllexport)
#endif
AshleysBrain
That is a good idea, however EXPORT was not previously defined. The compiler is having problems with the "C", thinking it is a string.
jp2code
+2  A: 

If your source file has a .c extension, the compiler you are using will compile it as C (not C++) and produce that error on the extern "C". If that is the case, then you need to use the /TP switch as you already noted or rename the file to .cpp. The other solution is to put #ifdefs around the extern:

#ifdef __cplusplus
extern "C"
#endif
Mark Wilkins
That was it! Thanks Mark Wilkins! Actually, I just renamed the files to .cpp ...and it worked! Thanks again! ~Joe
jp2code
A: 

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

Alexandre C.
+1  A: 

Forcing Compile As to Compile as C++ Code (/TP) - did you set this on all build configurations - debug/release x 32/x64 etc. I avoid using this option, much easier to name the file appropriately for the compiler to choose automatically.

You only need the "C" part of extern "C" if the file is C++ to turn off the name mangling.

I prefer to arrange the shared public header using this format, so you can include in C/C++ internally or 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
Greg Domjan
Perhaps I did not, but I certainly intended to! Visual Studio doesn't make it simple to compare settings between Debug and Release because the settings are on separate screens. Renaming all of my *.c files to include the .cpp extension fixed my issues, though, so I'm not looking back now! :)
jp2code