Re: Adding obj-c++ file to carbon project changes preprocessed header file types
Re: Adding obj-c++ file to carbon project changes preprocessed header file types
- Subject: Re: Adding obj-c++ file to carbon project changes preprocessed header file types
- From: Jens Alfke <email@hidden>
- Date: Mon, 11 Feb 2008 20:57:53 -0800
On 11 Feb '08, at 8:31 PM, Russ wrote:
As soon as I add the obj-c file to my existing project, xcode (3.0)
changes the
file type of my existing header files from c++ to objective-c. It
recompiles
the headers with "-x objective-c-header" or "-x objective-c++-
header" instead
of "-x c++-header" as normal. Of course, this completely hoses the
entire
compile with about a thousand error messages.
Short answer: The problem is the precompiled header (prefix file), not
compiling your C++ files. The solution is either to rename the .m file
to .mm, or to edit your .pch file and wrap an "#ifdef __cplusplus"
around any parts of it that are C++ specific.
The long answer:
For the most part, the compiler doesn't compile headers: it compiles
source files and uses the extension of the source file (.c, .cpp, .m)
to determine the language used. The headers just get merged in by the
preprocessor, which could care less what extension they are. Adding
a .m file to your project won't affect the other source files.
Your problem is probably coming from the one place where headers get
directly compiled: the prefix file of your project ("MyProject.pch" by
default). Since there's only one prefix file, it gets used for every
different language used in your project. It actually gets compiled
separately: once as C, once as C++, once as Obj-C...
When you add a .m file to your project, Xcode will generate an Obj-C
precompiled header from your prefix file, by compiling the prefix file
as Obj-C. If you have C++ syntax in headers included by your prefix
file, you need to wrap them in "#ifdef __cplusplus" to avoid having
the Obj-C precompiled header see them.
Or more easily, just rename your .m file to .mm to make it Objective-C+
+.
(That said, I suspect that NSCursor by itself isn't going to work
right in a Carbon app. But that's off-topic for this list.)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden