Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Precompiled Headers and gcc 3.3



On Thursday, June 26, 2003, at 8:21 PM, Nick Zitzmann wrote:

On Thursday, June 26, 2003, at 07:36 PM, Devang Patel wrote:

OK. If you've gone this far then let's debug this.

- Add compiler option -Winvalid-pch in OTHER_CFLAGS. GCC will emit info. about PCH validation. This will help to investigate why GCC is not using *.gch.

OK, this helps. It turns out the pre-comps weren't being used because I built them without debugging symbols, and I was building a target that did have debugging symbols turned on. Also, I found that Carbon & friends have to have pre-comps available for C, C++, and Objective-C or else GCC may ignore them (I was building C pre-comps for Carbon, and I apparently need to build Objective-C pre-comps in order to use Carbon in Objective-C source files).

Now I see that GCC 3.3 does support sets of pre-compiled headers, which straightens out some of these issues, but now, there's one thing I can't figure out... Now I'm seeing the following warning appear:

Controller.h:9:26: warning: /System/Library/Frameworks/AppKit.framework/Headers/AppKit.h.gch: not used because `ABS' is defined
Huh? Why would a #define macro (from NSObjCRuntime.h) throw this off, and what can I do about this? In some source files, it's also complaing about a -DDEBUG definition I threw into one build style's OTHER_CFLAGS, saying the pre-comp is "not used because `DEBUG' is defined". What can I do about these?

This is related to my question about .gch location. below...

- In terminal use 'file' command to check file type of *.gch. What does it say?

% file /System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h.gch
/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h.gch: data

- Where did you put .gch files ?

It says in the documentation to put the .gch files in the same directory as the rest of the headers, so that's what I've done.

But for system headers you want to avoid doing that. Pre-comps created for one set of compiler flags may not be appropriate for other projects or other compilations with different flags (say -DDEBUG). GCC 3.3 is more flexible. It allows you to place .gch files anywhere you like. Only catch is that you provide include path for that location in such a way that when compiler is looking for foo.h, it stumbles across foo.h.gch first. (When compiler is looking for foo.h in include paths, it also keeps an eye for foo.h.gch).

So if you put .gch at /my_project_build/my_project_precomps/foo.h.gch then provide -I /my_project_build/my_project/precomps to compiler.

GCC 3.3 pre-compiled header has one limitation. In one compiler invocation, it can use only one pre-compiled header. So what you want to do is,

(1) Create a new header, say MyPrefixHeader.h
Include main headers for large frameworks you use in MyPrefixHeader.h. Also add large headers from your project that you do not change frequently.
(2) Include MyPrefixHeader.h in all your source file as first include.
(3) Make MyPrefixHeader.h.gch. You know how to do this. Make sure, you supply all OTHER_CFLAGS flags to compiler while making .gch.
(4) Supply include paths for .gch

XCode takes care of steps (2), (3) and (4).

You may want to fine tune pre-compiled headers by including as many headers as you can in MyPrefixHeader.h. Follow step(1) and (2) and make sure your project builds. If your project do not build after step (2) then you have added conflicting headers in MyPrefixHeader.h. If you do not want to take advantage of MyPrefixHeader.h.gch while building one or two source files (because of conflicts) then do not include MyPrefixHeader.h in those source files. Once you clear step(2) then move to step (3) and (4). Like optimizations, it is worth to spend time to fine tune pre-comps for a large project.

If this is confusing, feel free to ask questions.

-Devang
_______________________________________________
projectbuilder-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/projectbuilder-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Precompiled Headers and gcc 3.3 (From: Nick Zitzmann <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.