Re: PCH being precompiled twice
Re: PCH being precompiled twice
- Subject: Re: PCH being precompiled twice
- From: "E. Wing" <email@hidden>
- Date: Tue, 29 Nov 2005 13:04:47 -0800
> From: Steve Mills
> At some point, Xcode has started procompiling my .pch twice. By
> looking at the build transcript, I see that one is correctly being
> compiled as C++, but the 2nd one (the one that generates hundreds of
> errors) is being compiled as regular C.
>
> Any idea why this is happening? I think it started after I added a
> new folder of files to my project. These are portable files (for out
> PC and Mac projects). The only oddity is that the use .cpp instead
> of .cp as their extension. Could that confuse Xcode?
>
>From my observations (and I make no claims this is actually what is
happening), Xcode seems to process the prcompiled header once for
each language you use in your code. So if you have both pure C code
and C++ code in your project, the header seems to get compiled twice
(once for each language). If you have C code, Obj-C code, and C++ code
it gets compiled 3 times.
So it is possible you might have C code in your project, or one of
your C++ headers has invoked extern "C" to request C style linkage.
Anyway, whatever the reason, the easiest and most robust way to deal
with this behavior is to place "language guards" in your precompiled
header. So you might have a pch that looks like this:
/* For C stuff which works everywhere, no guard is needed. */
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
#include <iostream>
#include <string>
#endif /* __cplusplus */
#ifdef __OBJC__
#include <Cocoa/Cocoa.h>
#endif /* __OBJC__ */
/* Maybe for Obj-C++ ??? */
#if defined(__cplusplus) && defined(__OBJC__)
#include "SomeObjCppStuff.h"
#endif
-Eric
_______________________________________________
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