gcc: Objective-C and Objective-C++ Dialect Options
1
1 3.6 Options Controlling Objective-C and Objective-C++ Dialects
1 ==============================================================
1
1 (NOTE: This manual does not describe the Objective-C and Objective-C++
11 languages themselves. ⇒Language Standards Supported by GCC
Standards, for references.)
1
1 This section describes the command-line options that are only
1 meaningful for Objective-C and Objective-C++ programs. You can also use
1 most of the language-independent GNU compiler options. For example, you
1 might compile a file 'some_class.m' like this:
1
1 gcc -g -fgnu-runtime -O -c some_class.m
1
1 In this example, '-fgnu-runtime' is an option meant only for Objective-C
1 and Objective-C++ programs; you can use the other options with any
1 language supported by GCC.
1
1 Note that since Objective-C is an extension of the C language,
1 Objective-C compilations may also use options specific to the C
1 front-end (e.g., '-Wtraditional'). Similarly, Objective-C++
1 compilations may use C++-specific options (e.g., '-Wabi').
1
1 Here is a list of options that are _only_ for compiling Objective-C and
1 Objective-C++ programs:
1
1 '-fconstant-string-class=CLASS-NAME'
1 Use CLASS-NAME as the name of the class to instantiate for each
1 literal string specified with the syntax '@"..."'. The default
1 class name is 'NXConstantString' if the GNU runtime is being used,
1 and 'NSConstantString' if the NeXT runtime is being used (see
1 below). The '-fconstant-cfstrings' option, if also present,
1 overrides the '-fconstant-string-class' setting and cause '@"..."'
1 literals to be laid out as constant CoreFoundation strings.
1
1 '-fgnu-runtime'
1 Generate object code compatible with the standard GNU Objective-C
1 runtime. This is the default for most types of systems.
1
1 '-fnext-runtime'
1 Generate output compatible with the NeXT runtime. This is the
1 default for NeXT-based systems, including Darwin and Mac OS X. The
1 macro '__NEXT_RUNTIME__' is predefined if (and only if) this option
1 is used.
1
1 '-fno-nil-receivers'
1 Assume that all Objective-C message dispatches ('[receiver
1 message:arg]') in this translation unit ensure that the receiver is
1 not 'nil'. This allows for more efficient entry points in the
1 runtime to be used. This option is only available in conjunction
1 with the NeXT runtime and ABI version 0 or 1.
1
1 '-fobjc-abi-version=N'
1 Use version N of the Objective-C ABI for the selected runtime.
1 This option is currently supported only for the NeXT runtime. In
1 that case, Version 0 is the traditional (32-bit) ABI without
1 support for properties and other Objective-C 2.0 additions.
1 Version 1 is the traditional (32-bit) ABI with support for
1 properties and other Objective-C 2.0 additions. Version 2 is the
1 modern (64-bit) ABI. If nothing is specified, the default is
1 Version 0 on 32-bit target machines, and Version 2 on 64-bit target
1 machines.
1
1 '-fobjc-call-cxx-cdtors'
1 For each Objective-C class, check if any of its instance variables
1 is a C++ object with a non-trivial default constructor. If so,
1 synthesize a special '- (id) .cxx_construct' instance method which
1 runs non-trivial default constructors on any such instance
1 variables, in order, and then return 'self'. Similarly, check if
1 any instance variable is a C++ object with a non-trivial
1 destructor, and if so, synthesize a special '- (void)
1 .cxx_destruct' method which runs all such default destructors, in
1 reverse order.
1
1 The '- (id) .cxx_construct' and '- (void) .cxx_destruct' methods
1 thusly generated only operate on instance variables declared in the
1 current Objective-C class, and not those inherited from
1 superclasses. It is the responsibility of the Objective-C runtime
1 to invoke all such methods in an object's inheritance hierarchy.
1 The '- (id) .cxx_construct' methods are invoked by the runtime
1 immediately after a new object instance is allocated; the '- (void)
1 .cxx_destruct' methods are invoked immediately before the runtime
1 deallocates an object instance.
1
1 As of this writing, only the NeXT runtime on Mac OS X 10.4 and
1 later has support for invoking the '- (id) .cxx_construct' and '-
1 (void) .cxx_destruct' methods.
1
1 '-fobjc-direct-dispatch'
1 Allow fast jumps to the message dispatcher. On Darwin this is
1 accomplished via the comm page.
1
1 '-fobjc-exceptions'
1 Enable syntactic support for structured exception handling in
1 Objective-C, similar to what is offered by C++. This option is
1 required to use the Objective-C keywords '@try', '@throw',
1 '@catch', '@finally' and '@synchronized'. This option is available
1 with both the GNU runtime and the NeXT runtime (but not available
1 in conjunction with the NeXT runtime on Mac OS X 10.2 and earlier).
1
1 '-fobjc-gc'
1 Enable garbage collection (GC) in Objective-C and Objective-C++
1 programs. This option is only available with the NeXT runtime; the
1 GNU runtime has a different garbage collection implementation that
1 does not require special compiler flags.
1
1 '-fobjc-nilcheck'
1 For the NeXT runtime with version 2 of the ABI, check for a nil
1 receiver in method invocations before doing the actual method call.
1 This is the default and can be disabled using '-fno-objc-nilcheck'.
1 Class methods and super calls are never checked for nil in this way
1 no matter what this flag is set to. Currently this flag does
1 nothing when the GNU runtime, or an older version of the NeXT
1 runtime ABI, is used.
1
1 '-fobjc-std=objc1'
1 Conform to the language syntax of Objective-C 1.0, the language
1 recognized by GCC 4.0. This only affects the Objective-C additions
1 to the C/C++ language; it does not affect conformance to C/C++
1 standards, which is controlled by the separate C/C++ dialect option
1 flags. When this option is used with the Objective-C or
1 Objective-C++ compiler, any Objective-C syntax that is not
1 recognized by GCC 4.0 is rejected. This is useful if you need to
1 make sure that your Objective-C code can be compiled with older
1 versions of GCC.
1
1 '-freplace-objc-classes'
1 Emit a special marker instructing 'ld(1)' not to statically link in
1 the resulting object file, and allow 'dyld(1)' to load it in at run
1 time instead. This is used in conjunction with the
1 Fix-and-Continue debugging mode, where the object file in question
1 may be recompiled and dynamically reloaded in the course of program
1 execution, without the need to restart the program itself.
1 Currently, Fix-and-Continue functionality is only available in
1 conjunction with the NeXT runtime on Mac OS X 10.3 and later.
1
1 '-fzero-link'
1 When compiling for the NeXT runtime, the compiler ordinarily
1 replaces calls to 'objc_getClass("...")' (when the name of the
1 class is known at compile time) with static class references that
1 get initialized at load time, which improves run-time performance.
1 Specifying the '-fzero-link' flag suppresses this behavior and
1 causes calls to 'objc_getClass("...")' to be retained. This is
1 useful in Zero-Link debugging mode, since it allows for individual
1 class implementations to be modified during program execution. The
1 GNU runtime currently always retains calls to
1 'objc_get_class("...")' regardless of command-line options.
1
1 '-fno-local-ivars'
1 By default instance variables in Objective-C can be accessed as if
1 they were local variables from within the methods of the class
1 they're declared in. This can lead to shadowing between instance
1 variables and other variables declared either locally inside a
1 class method or globally with the same name. Specifying the
1 '-fno-local-ivars' flag disables this behavior thus avoiding
1 variable shadowing issues.
1
1 '-fivar-visibility=[public|protected|private|package]'
1 Set the default instance variable visibility to the specified
1 option so that instance variables declared outside the scope of any
1 access modifier directives default to the specified visibility.
1
1 '-gen-decls'
1 Dump interface declarations for all classes seen in the source file
1 to a file named 'SOURCENAME.decl'.
1
1 '-Wassign-intercept (Objective-C and Objective-C++ only)'
1 Warn whenever an Objective-C assignment is being intercepted by the
1 garbage collector.
1
1 '-Wno-protocol (Objective-C and Objective-C++ only)'
1 If a class is declared to implement a protocol, a warning is issued
1 for every method in the protocol that is not implemented by the
1 class. The default behavior is to issue a warning for every method
1 not explicitly implemented in the class, even if a method
1 implementation is inherited from the superclass. If you use the
1 '-Wno-protocol' option, then methods inherited from the superclass
1 are considered to be implemented, and no warning is issued for
1 them.
1
1 '-Wselector (Objective-C and Objective-C++ only)'
1 Warn if multiple methods of different types for the same selector
1 are found during compilation. The check is performed on the list
1 of methods in the final stage of compilation. Additionally, a
1 check is performed for each selector appearing in a
1 '@selector(...)' expression, and a corresponding method for that
1 selector has been found during compilation. Because these checks
1 scan the method table only at the end of compilation, these
1 warnings are not produced if the final stage of compilation is not
1 reached, for example because an error is found during compilation,
1 or because the '-fsyntax-only' option is being used.
1
1 '-Wstrict-selector-match (Objective-C and Objective-C++ only)'
1 Warn if multiple methods with differing argument and/or return
1 types are found for a given selector when attempting to send a
1 message using this selector to a receiver of type 'id' or 'Class'.
1 When this flag is off (which is the default behavior), the compiler
1 omits such warnings if any differences found are confined to types
1 that share the same size and alignment.
1
1 '-Wundeclared-selector (Objective-C and Objective-C++ only)'
1 Warn if a '@selector(...)' expression referring to an undeclared
1 selector is found. A selector is considered undeclared if no
1 method with that name has been declared before the '@selector(...)'
1 expression, either explicitly in an '@interface' or '@protocol'
1 declaration, or implicitly in an '@implementation' section. This
1 option always performs its checks as soon as a '@selector(...)'
1 expression is found, while '-Wselector' only performs its checks in
1 the final stage of compilation. This also enforces the coding
1 style convention that methods and selectors must be declared before
1 being used.
1
1 '-print-objc-runtime-info'
1 Generate C header describing the largest structure that is passed
1 by value, if any.
1