Re: Preventing name mangling of exported symbols in a c++ file
Re: Preventing name mangling of exported symbols in a c++ file
- Subject: Re: Preventing name mangling of exported symbols in a c++ file
- From: Steve Checkoway <email@hidden>
- Date: Tue, 3 Jan 2006 22:16:42 -0800
On Jan 3, 2006, at 10:48 AM, Eric Albert wrote:
You'll want to define each of your functions in PublicStuff.cp as
extern "C", like this:
extern "C" void SomeFunction(const UInt32 value) {
// real code goes here
}
I often see people do something like this in a prefix file:
#ifdef __cplusplus
#define EXPORT extern "C"
#else
#define EXPORT
#endif
and then write their function definitions like this:
EXPORT void SomeFunction(const UInt32 value) {
// real code goes here
}
That shouldn't be necessary (and doesn't seem to be for me). If a
function prototype is declared extern "C" then when the function is
defined it should not be mangled. For example:
$ cat mangled.cpp
extern "C" { void foo(); }
void foo() { }
$ g++ -Wall -c mangled.cpp
$ nm mangled.o
00000000 T _foo
00000000 A _foo.eh
On the other hand, if the PublicStuff.cp file is not including
PublicStuff.h then the symbol will be mangled (something like
__Z3foov in my example--ugh, that's almost scary that I was right)
since nothing is informing the compiler that it should use C linkage.
- Steve
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden