Re: Mixing C and C++ in the same in a CFPlugIn
Re: Mixing C and C++ in the same in a CFPlugIn
- Subject: Re: Mixing C and C++ in the same in a CFPlugIn
- From: Rick Steele <email@hidden>
- Date: Sat, 18 Dec 2004 14:43:16 -0800
Thanks you! Hit the nail right on the head! and thank you Joar for trying.
At 10:47 PM +0100 12/18/04, Tomas Zahradnicky wrote:
Does anyone know what might cause Xcode to complain when
Sure.
You have a source file called "Something.c++"
You have a source file called "SomethingElse.c" which calls a
routine in "Something.c++"
The reason is that C++ mangles function/member names differently
from C since C++ has to preserve argument information (because of
overloading) in contrary to C.
If you want to call a function defined in C++ from C code, you have
to precede C++ function's prototype with
extern "C"
or enclose functions' prototypes in:
extern "C" {
int MyCPPFunction1(int);
int MyCPPFunction2(char*);
int MyCPPFunction3(void);
}
Using extern "C" will cause function's symbol name be mangled in C
therefore C linker will find the C name it expects.
If you are not sure, you can easily check how your function's name
got mangled with nm. You should see
_MyCPPFunction1
_MyCPPFunction2
_MyCPPFunction3
instead of something like this:
_ZN14MyCPPFunction1EiE
_ZN14MyCPPFunction2EpcE
_ZN14MyCPPFunction3EvE
Cheers,
Tomas
--
# Ing. Tomas Zahradnicky, Jr.
# The Czech Technical University
# Dept of Computer Science, FEE-CTU Prague
_______________________________________________
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