By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,441 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,441 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 11 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
pe***@yahoo.com wrote:
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.
Nov 11 '05 #2

P: n/a
Ian
pe***@yahoo.com wrote:
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
Nov 11 '05 #3

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

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

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.