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: Matt Gough <email@hidden>
- Date: Wed, 4 Jan 2006 09:44:24 +0000
On 4 Jan 2006, at 06:16, Steve Checkoway 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 was right that it wasn't necessary. The names were not actually
being mangled at all. What I thought were the mangled names of my
exported functions were actually the correctly mangled names of some
private stuff.
Once I got used to using nm, it was obvious why the stuff in my
Exported Symbols file was not being found. I hadn't preceded each
symbol with an underscore. e.g:
_SomeFunction
However, this leads me on to another problem that CodeWarrior doesn't
have:
My framework needs to use a few source files from a large source
library (PowerPlant as it happens). The few files that it uses can
call functions in other source files. However none of the functions I
am using would result in any of these other functions being called.
As such, in CW I do not need to add the unneeded source files to my
project. Unfortunately this does not seem to be the case with Xcode.
The linker is complaining about Undefined symbols that are not
needed. It should know they are not needed as they are not in my
Exported Symbols file. The simple solution would seem to be to add
the source files containing the undefined symbols (there are only 5
such symbols). Unfortunately this does not work as the problem then
ripples along to all of the functions that that those files call that
are in other files not yet added to the project.
Is there some linker settings I can use that will alleviate this, or
do I really need to add this ever expanding chain of unneeded files
to my project?
I could just define some stub versions of these functions, but that
might lead to future problems if ever the real versions were needed.
Thanks again for any help
Matt Gough
_______________________________________________
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