Re: Mixing obective-C and c++
Re: Mixing obective-C and c++
- Subject: Re: Mixing obective-C and c++
- From: Chris Hanson <email@hidden>
- Date: Sat, 7 Apr 2007 09:26:22 -0700
On Apr 7, 2007, at 9:03 AM, Livio Isaia wrote:
Let's say I have
theCFile.h declaring theCProcedure,
theCFile.c++ containing theCProcedure
and theCocoaFile.m calling theCProcedure.
All files are in the same project; when building everything seems
ok; I set "#include "theCFile.h"" in theCocoaFile.m; the target of
theCFile.c++ is the target application...
I shouldn't be surprised if it couldn't link with some libraries
called from theCFile.c++, but linking with theCFile.o?
You need to tell the compiler to generate theCProcedure with C linkage
rather than C++ so its name doesn't get mangled to include type
information.
In theCFile.h:
#ifdef __cplusplus
extern "C" {
#endif
float theProcedure(int foo); // or whatever its prototype is
#ifdef __cplusplus
}
#endif
This ensures that, even when included from a source file being
compiled as C++, theProcedure will be generated with or called via an
unmangled name.
-- Chris
_______________________________________________
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