Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Per-File Compiler Flags

The build system provides facilities for customizing the build process for groups of files assigned to specific build phases. It includes the Other C Flags (OTHER_CFLAGS), Other C++ Flags (OTHER_CPLUSPLUSFLAGS), Other Warning Flags (WARNING_CFLAGS), and Preprocessor Macros (GCC_PREPROCESSOR_DEFINITIONS) build settings, among many others, to customize the invocation of the compiler when processing C-based source files. However, sometimes it’s necessary to specify compiler flags on a per-file basis. For example, in a project that treats warnings as errors in general, you may have a set of cross-platform source files where it’s more convenient to allow some warnings to remain.

To set compiler flags for a file, select the source file and open an inspector or Info window. Click Build to open the Build pane, as shown in Figure 25-12. Type any compiler flags you wish to assign to the file in the Additional Compiler Flags for Target field. Multiple flags should be separated by spaces. You can use multiple selection to assign compiler flags to a subset of the files in a target. Note that the Build pane is only available for files containing source code.

For each target that a file belongs to, Xcode maintains a separate list of compiler flags assigned to a file. To specify compiler flags for use with a file when it is built as part of a particular target, select the file from the appropriate build phase in that target and open an inspector window, as described above. If you open an inspector window for the file from any other source or smart group in the project window, Xcode assumes you want to assign compiler flags to the file in the active target; thus, the Build pane is only available if the file is part of the active target.


Figure 25-12  The Build pane of the file inspector

Figure 25-12 The Build pane of the file inspector

When the build system constructs the command-line invocation for the tool that processes the source file, it adds the additional compiler flags assigned to the file to the invocation. The build system doesn’t validate the flags you add; that is, it doesn’t test whether the compiler actually supports the options you add, and it doesn’t investigate whether the options you add conflict with the ones it generates. If you add a group of compiler options and flags for a file and the file no longer compiles, you should remove all the flags you added and add them back one at a time, making sure the file compiles after you add each flag. You should also consult the tool’s documentation to learn about possible conflicts.

The additional compiler flags specified for a file will always be used when the file is processed as part of a build and cannot be overridden in any of the build setting layers. See “Build Settings” for information on build settings.



< Previous PageNext Page > Hide TOC


Last updated: 2006-11-07




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice