For the curious, here are the build settings I use and recommend, when using XCode for Mac and iOS applications.
Most of them activates the highest possible error reporting level.
At first sight, it may seem it's hard to code with those settings, but it really saves you a lot of time debugging your app.
Most of the problems usually encountered in application development, using Objective-C, comes from the Objective-C runtime. And sometimes, those problems are hard to debug, because of the dynamic nature of the Objective-C language.
Activating most of the compiler error flags will save you time, as the compilation will fail, with an error message, instead of leaving you with a app that crashed for apparently no reason.
About the "Unused Parameters" setting, if you really don't use a parameter, you can cast it to void
, so the compiler won't complain:
void some_func( int some_param ) { ( void )some_param; /* ... */ }
When dealing with methods returning an id
type, you may sometimes have to cast the object, to let the compiler knows about the type:
[ ( ClassName * )[ someObject getIdObject ] someMethod ];
So here are the settings, grouped as in the XCode build settings panel.
DEAD_CODE_STRIPPING = YES
Activating this setting causes the -dead_stri
p flag to be passed to ld(1)
via cc(1)
to turn on dead code stripping.
If this option is selected, -gfull
(not -gused
) must be used to generate debugging symbols in order to have them correctly stripped.
[DEAD_CODE_STRIPPING, -dead_strip]
LINK_WITH_STANDARD_LIBRARIES = YES
If this setting activated, then the compiler driver will automatically pass its standard libraries to the linker to use during linking.
If desired, this flag can be used to disable linking with the standard libraries, and then individual libraries can be passed as Other Linker Flags.
[LINK_WITH_STANDARD_LIBRARIES, -nostdlib]
INFOPLIST_OUTPUT_FORMAT = binary
Specifies the output encoding for the output Info.plist (by default, the output encoding will be unchanged from the input). The output endcodings can be 'binary' or 'XML'.
[INFOPLIST_OUTPUT_FORMAT]
GCC_GENERATE_DEBUGGING_SYMBOLS = NO
(Permitted for «Debug» configuration)
Enables or disables generation of debug symbols.
When debug symbols are enabled, the level of detail can be controlled by the build 'Level of Debug Symbols' setting.
[GCC_GENERATE_DEBUGGING_SYMBOLS]
GCC_DYNAMIC_NO_PIC = YES
(No permitted for «Debug» configuration, or for shared libraries)
Faster function calls for applications. Not appropriate for shared libraries (which need to be position-independent).
[GCC_DYNAMIC_NO_PIC, -mdynamic-no-pic]
GCC_INLINES_ARE_PRIVATE_EXTERN = YES
When enabled, out-of-line copies of inline methods are declared private extern
.
[GCC_INLINES_ARE_PRIVATE_EXTERN, -fvisibility-inlines-hidden]
GCC_REUSE_STRINGS = YES
Reuse string literals.
[GCC_REUSE_STRINGS, -fwritable-strings]
GCC_ENABLE_OBJC_GC = Unsupported
Compiles code to use Garbage Collector write-barrier assignment primitives within the Objective-C runtime.
Code is marked as being GC capable.
An application marked GC capable will be started by the runtime with Garbage Collection enabled.
All Objective-C code linked or loaded by this application must also be GC capable.
Code compiled as GC Required is presumed to not use traditional Cocoa retain/release methods and may not be loaded into an application that is not running with Garbage Collection enabled.
Code compiled as GC Supported is presumed to also contain traditional retain/release method logic and can be loaded into any application.
Garbage Collection is only supported on Mac OS X 10.5 and later.
[GCC_ENABLE_OBJC_GC, -fobjc-gc | -fobjc-gc-only]
GCC_OPTIMIZATION_LEVEL = Fastest, Smallest [-Os]
[-O, -O1]
[-O2]
[-O3]
[-Os]
[GCC_OPTIMIZATION_LEVEL]
GCC_C_LANGUAGE_STANDARD = C89
(C99 permitted if absolutely necessary, especially on iOS)
Choose a standard or non-standard C language dialect.
[-ansi]
asm
, inline
, and typeof
keywords
(but not the equivalent __asm__
, __inline__
, and __typeof__
forms), and the '//' syntax for comments.
[-std=c89]
[-std=gnu89]
[-std=c99]
[-std=gnu99]
Please see the full GCC manual for the full definition of all these settings on the C dialect:
http://developer.apple.com/documentation/DeveloperTools/gcc-4.2.1/gcc/C-Dialect-Options.html
[GCC_C_LANGUAGE_STANDARD]
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
Warn whenever a switch statement has an index of enumeral type and lacks a case for one or more of the named codes of that enumeration.
The presence of a default label prevents this warning.
Case labels outside the enumeration range also provoke warnings when this option is used.
[GCC_WARN_CHECK_SWITCH_STATEMENTS, -Wswitch]
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES
Warn about violations of the following style guidelines from Scott Meyers' Effective C++ book:
operator=
return a reference to *this
.
&&
, ||
, or, .
If you use this option, you should be aware that the standard library headers do not obey all of these guidelines; you can use grep -v
to filter out those warnings.
[GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS, -Weffc++]
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
Warn about four-char literals (e.g., MacOS-style OSTypes: 'APPL'
).
[GCC_WARN_FOUR_CHARACTER_CONSTANTS, -Wfour-char-constants]
GCC_WARN_ABOUT_GLOBAL_CONSTRUCTORS = YES
Warn about namespace scope data that requires construction or destruction, or functions that use the constructor attribute or the destructor attribute.
Additionally warn if the Objective-C GNU runtime is used to initialize various metadata.
[GCC_WARN_ABOUT_GLOBAL_CONSTRUCTORS, -Wglobal-constructors]
GCC_WARN_SHADOW = YES
Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed.
[GCC_WARN_SHADOW, -Wshadow]
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
Warn if a value is implicitly converted from a 64 bit type to a 32 bit type.
[GCC_WARN_64_TO_32_BIT_CONVERSION, -Wshorten-64-to-32]
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES
Warn if methods required by a protocol are not implemented in the class adopting it.
Only applies to Objective-C and Objective-C++.
[GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL, -Wno-protocol]
GCC_WARN_INHIBIT_ALL_WARNINGS = NO
Inhibit all warning messages.
[GCC_WARN_INHIBIT_ALL_WARNINGS, -w]
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
Warn if an aggregate or union initializer is not fully bracketed.
Example, Here initializer for a is not fully bracketed, but that for b is fully bracketed.
int a[ 2 ][ 2 ] = { 0, 1, 2, 3 }; int b[ 2 ][ 2 ] = { { 0, 1 }, { 2, 3 } };
[GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED, -Wmissing-braces]
GCC_WARN_ABOUT_RETURN_TYPE = YES
Causes warnings to be emitted when a function with a defined return type (not void) contains a return statement without a return-value.
Also emits a warning when a function is defined without specifying a return type.
[GCC_WARN_ABOUT_RETURN_TYPE, -Wreturn-type]
GCC_WARN_MISSING_PARENTHESES = YES
Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about.
Also warn about constructions where there may be confusion to which if statement an else branch belongs.
Here is an example of such a case:
{ if( a ) if( b ) foo(); else bar(); }
In C, every else branch belongs to the innermost possible if statement, which in this example is if (b).
This is often not what the programmer expected, as illustrated in the above example by indentation the programmer chose.
When there is the potential for this confusion, GCC will issue a warning when this flag is specified.
To eliminate the warning, add explicit braces around the innermost if statement so there is no way the else could belong to the enclosing if.
The resulting code would look like this:
{ if( a ) { if( b ) foo(); else bar(); } }
[GCC_WARN_MISSING_PARENTHESES, -Wparentheses]
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
Warn if a structure's initializer has some fields missing.
For example, the following code would cause such a warning, because "x.h"
is implicitly zero:
struct s { int f, g, h; }; struct s x = { 3, 4 };
This option does not warn about designated initializers, so the following modification would not trigger a warning:
struct s { int f, g, h; }; struct s x = { .f = 3, .g = 4 };
[GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS, -Wmissing-field-initializers]
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
Causes warnings to be emitted about missing prototypes.
[GCC_WARN_ABOUT_MISSING_PROTOTYPES, -Wmissing-prototypes]
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
Warn when a source file does not end with a newline.
[GCC_WARN_ABOUT_MISSING_NEWLINE, -Wnewline-eof]
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = NO
Warn if multiple methods of different types for the same selector are found during compilation.
The check is performed on the list of methods in the final stage of compilation.
Additionally, a check is performed for each selector appearing in a "@selector(...)"
expression, and a corresponding method for that selector has been found during compilation.
Because these checks scan the method table only at the end of compilation, these warnings are not produced if the final stage of compilation is not reached, for example because an error is found during compilation, or because the -fsyntax-only option is being used.
[GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR, -Wselector]
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
Warn when a class declares an nonvirtual destructor that should probably be virtual, because it looks like the class will be used polymorphically.
[GCC_WARN_NON_VIRTUAL_DESTRUCTOR, -Wnon-virtual-dtor]
This is only active for C++ or Objective-C++ sources.
WARNING_CFLAGS = -Wall -Wextra -Werror -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wdeclaration-after-statement
Space-separated list of additional warning flags to pass to the compiler. Use this setting if Xcode does not already provide UI for a particular compiler warning flag.
[WARNING_CFLAGS]
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
Warn when a function declaration hides virtual functions from a base class.
[GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS, -Woverloaded-virtual]
For example, in:
struct A { virtual void f(); }; struct B: public A { void f( int ); };
the A
class version of f()
is hidden in B
, and code like this:
B * b; b->f();
will fail to compile. This setting only applies to C++ and Objective-C++ sources.
GCC_WARN_PEDANTIC = YES
Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++.
For ISO C, follows the version of the ISO C standard specified by any -std
option used.
[GCC_WARN_PEDANTIC, -pedantic]
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES
Warn when pointers passed via arguments or assigned to a variable differ in sign.
[GCC_WARN_ABOUT_POINTER_SIGNEDNESS, -Wno-pointer-sign]
GCC_WARN_PROTOTYPE_CONVERSION = NO
Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype.
This includes conversions of fixed point to floating and vice versa, and conversions changing the width or signedness of a fixed point argument except when the same as the default promotion.
Also, warn if a negative integer constant expression is implicitly converted to an unsigned type.
For example, warn about the assignment "x = -1"
if "x" is unsigned.
But do not warn about explicit casts like (unsigned) -1
.
[GCC_WARN_PROTOTYPE_CONVERSION, -Wconversion]
GCC_WARN_SIGN_COMPARE = YES
Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned.
This warning is enabled by -W
, and by -Wall
in C++ only.
[GCC_WARN_SIGN_COMPARE, -Wsign-compare]
GCC_WARN_STRICT_SELECTOR_MATCH = YES
Warn if multiple methods with differing argument and/or return types are found for a given selector when attempting to send a message using this selector to a receiver of type "id" or "Class".
When this setting is disabled, the compiler will omit such warnings if any differences found are confined to types which share the same size and alignment.
[GCC_WARN_STRICT_SELECTOR_MATCH, -Wstrict-selector-match]
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES
Causes warnings about missing function prototypes to be treated as errors.
Only applies to C and Objective-C.
[GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS, -Werror-implicit-function-declaration]
GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = NO
Enabling this option will downgrade messages about nonconformant code from errors to warnings.
By default, G++ effectively sets -pedantic-errors
without -pedantic
; this option reverses that.
This behavior and this option are superseded by -pedantic
, which works as it does for GNU C.
[GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS, -fpermissive]
GCC_TREAT_WARNINGS_AS_ERRORS = YES
Enabling this option causes all warnings to be treated as errors.
[GCC_TREAT_WARNINGS_AS_ERRORS, -Werror]
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense.
[GCC_WARN_TYPECHECK_CALLS_TO_PRINTF, -Wno-format]
GCC_WARN_UNDECLARED_SELECTOR = YES
Warn if a "@selector(...)"
expression referring to an undeclared selector is found.
A selector is considered undeclared if no method with that name has been declared before the "@selector(...)"
expression, either explicitly in an @interface or @protocol declaration, or implicitly in an @implementation section.
This option always performs its checks as soon as a "@selector(...)"
expression is found, while -Wselector
only performs its checks in the final stage of compilation.
This also enforces the coding style convention that methods and selectors must be declared before being used.
[GCC_WARN_UNDECLARED_SELECTOR, -Wundeclared-selector]
GCC_WARN_UNINITIALIZED_AUTOS = YES
Warn if a variable might be clobbered by a setjmp call or if an automatic variable is used without prior initialization.
Detection of uninitialized automatic variable requires data flow analsys that is only enabled during optimized compilation.
Note that GCC cannot detect all cases where an automatic variable is initialized or all usage patterns that may lead to use prior to initialization.
[GCC_WARN_UNINITIALIZED_AUTOS, -Wuninitialized]
GCC_WARN_UNKNOWN_PRAGMAS = YES
Warn when a #pragma directive is encountered which is not understood by GCC.
If this command line option is used, warnings will even be issued for unknown pragmas in system header files.
This is not the case if the warnings were only enabled by the -Wall
command line option.
[GCC_WARN_UNKNOWN_PRAGMAS, -Wunknown-pragmas]
GCC_WARN_UNUSED_FUNCTION = YES
Warn whenever a static function is declared but not defined or a non-inline static function is unused.
[GCC_WARN_UNUSED_FUNCTION, -Wunused-function]
GCC_WARN_UNUSED_LABEL = YES
Warn whenever a label is declared but not used.
[GCC_WARN_UNUSED_LABEL, -Wunused-label]
GCC_WARN_UNUSED_PARAMETER = YES
Warn whenever a function parameter is unused aside from its declaration.
[GCC_WARN_UNUSED_PARAMETER, -Wunused-parameter]
GCC_WARN_UNUSED_VALUE = YES
Warn whenever a statement computes a result that is explicitly not used.
[GCC_WARN_UNUSED_VALUE, -Wunused-value]
GCC_WARN_UNUSED_VARIABLE = YES
Warn whenever a local variable or non-constant static variable is unused aside from its declaration.
[GCC_WARN_UNUSED_VARIABLE, -Wunused-variable]
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
Warn about the use of deprecated functions, variables, and types (as indicated by the 'deprecated' attribute).
[GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS, -Wno-deprecated-declarations]
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
Unchecking this setting will suppress warnings from applying the offsetof macro to a non-POD type.According to the 1998 ISO C++ standard, applying offsetof to a non-POD type is undefined.
In existing C++ implementations, however, offsetof typically gives meaningful results even when applied to certain kinds of non-POD types. (Such as a simple struct that fails to be a POD type only by virtue of having a constructor.)
This flag is for users who are aware that they are writing non-portable code and who have deliberately chosen to ignore the warning about it.
The restrictions on offsetof may be relaxed in a future version of the C++ standard.
[GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO, -Wno-invalid-offsetof]