Using "C" modifier to prevent C++ name mangling for DLL function??

P

perfb

have a C++ DLL that needs to be called be external non-C app that uses
C interface, but cant figure out how to export C++ DLL functions
without name mangling.

if I declare

_declspec(dllexport) void "C" foo(void)

then it compiles ok, but I dont see any foo exported when dumpbin the
dll

If I leave off the "C" then of course foo is exported but with mangled
name

tia for any tips/sarcasm
 
G

Gianni Mariani

have a C++ DLL that needs to be called be external non-C app that uses
C interface, but cant figure out how to export C++ DLL functions
without name mangling.

if I declare

_declspec(dllexport) void "C" foo(void)

then it compiles ok, but I dont see any foo exported when dumpbin the
dll

If I leave off the "C" then of course foo is exported but with mangled
name

tia for any tips/sarcasm

In standard C++ you can do this.

extern "C" {

void foo(void);

}

void foo(void) {}


- however, _declspec(dllexport) is somthing you'd be better off asking
an MS specific ng.
 
I

Ian

have a C++ DLL that needs to be called be external non-C app that uses
C interface, but cant figure out how to export C++ DLL functions
without name mangling.

if I declare

_declspec(dllexport) void "C" foo(void)

then it compiles ok, but I dont see any foo exported when dumpbin the
dll

If I leave off the "C" then of course foo is exported but with mangled
name

tia for any tips/sarcasm
You'll have better luck on a microsoft specific group.

Ian
 
E

ecky-l

which compiler do you use? If MinGW / g++, have a look at this page:
http://www.mingw.org/MinGWiki/index.php/sample DLL

Important is the lower part: compile with -no-undefined
--enable-pseudo-runtime-reloc to export all symbols. But you must not
have *any* __declspec(dllexport) declarations in your code, if you want
to do this.
Take a close look on the remarks on compiler compatibility! Virtually
it means, if your client app was compiled with a different compiler
than the one you use (e.g. you use g++, the client app was compiled
with MSVC), C++ symbols can't be imported by the client app at all. You
better use the same compiler as the people who build the client app.


Eckhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top