Re: Solved: "C" Functions Won't Link Between .mm Files
Re: Solved: "C" Functions Won't Link Between .mm Files
- Subject: Re: Solved: "C" Functions Won't Link Between .mm Files
- From: Stefan Werner <email@hidden>
- Date: Wed, 14 Dec 2005 07:57:37 +0100
Hi Jerry,
Date: Tue, 13 Dec 2005 21:21:42 -0800
From: Jerry Krinock <email@hidden>
Subject: Solved: "C" Functions Won't Link Between .mm Files
If instead I linked it with Build Configuration "Deployment", I got
a bunch
of "Undefined symbol" errors during linking. It looked like I got
an error
for each plain-old C function such as "void MyFunction(int
someArg)" which
was called in one file but defined in another file.
I discovered hat the problem was only occurring if one of the files
had the
.mm extension instead of .m. (This project was born as Objective-C+
+).
Removing .mm files, changing all .mm extentions to .m, and re-
adding the
files fixed the problem.
Is this a bug, a feature, or another CodeWarrior exit exam which I
have
failed? (It links fine with the .mm extensions in CodeWarrior.)
It's probably because gcc compiles files with C++ name mangling as
soon as it's called .mm. To avoid name mangling, you need to declare
your functions as
extern "C" void MyCFunction();
in the C+++/ObjC++ code. If you declare the functions in a header
file, you can do this to make it easier:
#ifdef __cplusplus
extern "C" {
#endif
void MyFunc1();
char* MyFunc2(int a);
#ifdef __cplusplus
}
#endif
-Stefan
_______________________________________________
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