1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<div class="section-level-extent" id="Objective-C-and-Objective-C_002b_002b-Dialect-Options"> <div class="nav-panel"> <p> Next: <a href="diagnostic-message-formatting-options" accesskey="n" rel="next">Options to Control Diagnostic Messages Formatting</a>, Previous: <a href="c_002b_002b-dialect-options" accesskey="p" rel="prev">Options Controlling C++ Dialect</a>, Up: <a href="invoking-gcc" accesskey="u" rel="up">GCC Command Options</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Options-Controlling-Objective-C-and-Objective-C_002b_002b-Dialects"><span>3.6 Options Controlling Objective-C and Objective-C++ Dialects<a class="copiable-link" href="#Options-Controlling-Objective-C-and-Objective-C_002b_002b-Dialects"> ¶</a></span></h1> <p>(NOTE: This manual does not describe the Objective-C and Objective-C++ languages themselves. See <a class="xref" href="standards">Language Standards Supported by GCC</a>, for references.) </p> <p>This section describes the command-line options that are only meaningful for Objective-C and Objective-C++ programs. You can also use most of the language-independent GNU compiler options. For example, you might compile a file <samp class="file">some_class.m</samp> like this: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">gcc -g -fgnu-runtime -O -c some_class.m</pre>
</div> <p>In this example, <samp class="option">-fgnu-runtime</samp> is an option meant only for Objective-C and Objective-C++ programs; you can use the other options with any language supported by GCC. </p> <p>Note that since Objective-C is an extension of the C language, Objective-C compilations may also use options specific to the C front-end (e.g., <samp class="option">-Wtraditional</samp>). Similarly, Objective-C++ compilations may use C++-specific options (e.g., <samp class="option">-Wabi</samp>). </p> <p>Here is a list of options that are <em class="emph">only</em> for compiling Objective-C and Objective-C++ programs: </p> <dl class="table"> <dt>
<span><code class="code">-fconstant-string-class=<var class="var">class-name</var></code><a class="copiable-link" href="#index-fconstant-string-class"> ¶</a></span>
</dt> <dd>
<p>Use <var class="var">class-name</var> as the name of the class to instantiate for each literal string specified with the syntax <code class="code">@"…"</code>. The default class name is <code class="code">NXConstantString</code> if the GNU runtime is being used, and <code class="code">NSConstantString</code> if the NeXT runtime is being used (see below). The <samp class="option">-fconstant-cfstrings</samp> option, if also present, overrides the <samp class="option">-fconstant-string-class</samp> setting and cause <code class="code">@"…"</code> literals to be laid out as constant CoreFoundation strings. </p> </dd> <dt>
<span><code class="code">-fgnu-runtime</code><a class="copiable-link" href="#index-fgnu-runtime"> ¶</a></span>
</dt> <dd>
<p>Generate object code compatible with the standard GNU Objective-C runtime. This is the default for most types of systems. </p> </dd> <dt>
<span><code class="code">-fnext-runtime</code><a class="copiable-link" href="#index-fnext-runtime"> ¶</a></span>
</dt> <dd>
<p>Generate output compatible with the NeXT runtime. This is the default for NeXT-based systems, including Darwin and Mac OS X. The macro <code class="code">__NEXT_RUNTIME__</code> is predefined if (and only if) this option is used. </p> </dd> <dt>
<span><code class="code">-fno-nil-receivers</code><a class="copiable-link" href="#index-fno-nil-receivers"> ¶</a></span>
</dt> <dd>
<p>Assume that all Objective-C message dispatches (<code class="code">[receiver
message:arg]</code>) in this translation unit ensure that the receiver is not <code class="code">nil</code>. This allows for more efficient entry points in the runtime to be used. This option is only available in conjunction with the NeXT runtime and ABI version 0 or 1. </p> </dd> <dt>
<span><code class="code">-fobjc-abi-version=<var class="var">n</var></code><a class="copiable-link" href="#index-fobjc-abi-version"> ¶</a></span>
</dt> <dd>
<p>Use version <var class="var">n</var> of the Objective-C ABI for the selected runtime. This option is currently supported only for the NeXT runtime. In that case, Version 0 is the traditional (32-bit) ABI without support for properties and other Objective-C 2.0 additions. Version 1 is the traditional (32-bit) ABI with support for properties and other Objective-C 2.0 additions. Version 2 is the modern (64-bit) ABI. If nothing is specified, the default is Version 0 on 32-bit target machines, and Version 2 on 64-bit target machines. </p> </dd> <dt>
<span><code class="code">-fobjc-call-cxx-cdtors</code><a class="copiable-link" href="#index-fobjc-call-cxx-cdtors"> ¶</a></span>
</dt> <dd>
<p>For each Objective-C class, check if any of its instance variables is a C++ object with a non-trivial default constructor. If so, synthesize a special <code class="code">- (id) .cxx_construct</code> instance method which runs non-trivial default constructors on any such instance variables, in order, and then return <code class="code">self</code>. Similarly, check if any instance variable is a C++ object with a non-trivial destructor, and if so, synthesize a special <code class="code">- (void) .cxx_destruct</code> method which runs all such default destructors, in reverse order. </p> <p>The <code class="code">- (id) .cxx_construct</code> and <code class="code">- (void) .cxx_destruct</code> methods thusly generated only operate on instance variables declared in the current Objective-C class, and not those inherited from superclasses. It is the responsibility of the Objective-C runtime to invoke all such methods in an object’s inheritance hierarchy. The <code class="code">- (id) .cxx_construct</code> methods are invoked by the runtime immediately after a new object instance is allocated; the <code class="code">- (void) .cxx_destruct</code> methods are invoked immediately before the runtime deallocates an object instance. </p> <p>As of this writing, only the NeXT runtime on Mac OS X 10.4 and later has support for invoking the <code class="code">- (id) .cxx_construct</code> and <code class="code">- (void) .cxx_destruct</code> methods. </p> </dd> <dt>
<span><code class="code">-fobjc-direct-dispatch</code><a class="copiable-link" href="#index-fobjc-direct-dispatch"> ¶</a></span>
</dt> <dd>
<p>Allow fast jumps to the message dispatcher. On Darwin this is accomplished via the comm page. </p> </dd> <dt>
<span><code class="code">-fobjc-exceptions</code><a class="copiable-link" href="#index-fobjc-exceptions"> ¶</a></span>
</dt> <dd>
<p>Enable syntactic support for structured exception handling in Objective-C, similar to what is offered by C++. This option is required to use the Objective-C keywords <code class="code">@try</code>, <code class="code">@throw</code>, <code class="code">@catch</code>, <code class="code">@finally</code> and <code class="code">@synchronized</code>. This option is available with both the GNU runtime and the NeXT runtime (but not available in conjunction with the NeXT runtime on Mac OS X 10.2 and earlier). </p> </dd> <dt>
<span><code class="code">-fobjc-gc</code><a class="copiable-link" href="#index-fobjc-gc"> ¶</a></span>
</dt> <dd>
<p>Enable garbage collection (GC) in Objective-C and Objective-C++ programs. This option is only available with the NeXT runtime; the GNU runtime has a different garbage collection implementation that does not require special compiler flags. </p> </dd> <dt>
<span><code class="code">-fobjc-nilcheck</code><a class="copiable-link" href="#index-fobjc-nilcheck"> ¶</a></span>
</dt> <dd>
<p>For the NeXT runtime with version 2 of the ABI, check for a nil receiver in method invocations before doing the actual method call. This is the default and can be disabled using <samp class="option">-fno-objc-nilcheck</samp>. Class methods and super calls are never checked for nil in this way no matter what this flag is set to. Currently this flag does nothing when the GNU runtime, or an older version of the NeXT runtime ABI, is used. </p> </dd> <dt>
<span><code class="code">-fobjc-std=objc1</code><a class="copiable-link" href="#index-fobjc-std"> ¶</a></span>
</dt> <dd>
<p>Conform to the language syntax of Objective-C 1.0, the language recognized by GCC 4.0. This only affects the Objective-C additions to the C/C++ language; it does not affect conformance to C/C++ standards, which is controlled by the separate C/C++ dialect option flags. When this option is used with the Objective-C or Objective-C++ compiler, any Objective-C syntax that is not recognized by GCC 4.0 is rejected. This is useful if you need to make sure that your Objective-C code can be compiled with older versions of GCC. </p> </dd> <dt>
<span><code class="code">-freplace-objc-classes</code><a class="copiable-link" href="#index-freplace-objc-classes"> ¶</a></span>
</dt> <dd>
<p>Emit a special marker instructing <code class="command">ld(1)</code> not to statically link in the resulting object file, and allow <code class="command">dyld(1)</code> to load it in at run time instead. This is used in conjunction with the Fix-and-Continue debugging mode, where the object file in question may be recompiled and dynamically reloaded in the course of program execution, without the need to restart the program itself. Currently, Fix-and-Continue functionality is only available in conjunction with the NeXT runtime on Mac OS X 10.3 and later. </p> </dd> <dt>
<span><code class="code">-fzero-link</code><a class="copiable-link" href="#index-fzero-link"> ¶</a></span>
</dt> <dd>
<p>When compiling for the NeXT runtime, the compiler ordinarily replaces calls to <code class="code">objc_getClass("…")</code> (when the name of the class is known at compile time) with static class references that get initialized at load time, which improves run-time performance. Specifying the <samp class="option">-fzero-link</samp> flag suppresses this behavior and causes calls to <code class="code">objc_getClass("…")</code> to be retained. This is useful in Zero-Link debugging mode, since it allows for individual class implementations to be modified during program execution. The GNU runtime currently always retains calls to <code class="code">objc_get_class("…")</code> regardless of command-line options. </p> </dd> <dt>
<span><code class="code">-fno-local-ivars</code><a class="copiable-link" href="#index-fno-local-ivars"> ¶</a></span>
</dt> <dd>
<p>By default instance variables in Objective-C can be accessed as if they were local variables from within the methods of the class they’re declared in. This can lead to shadowing between instance variables and other variables declared either locally inside a class method or globally with the same name. Specifying the <samp class="option">-fno-local-ivars</samp> flag disables this behavior thus avoiding variable shadowing issues. </p> </dd> <dt>
<span><code class="code">-fivar-visibility=<span class="r">[</span>public<span class="r">|</span>protected<span class="r">|</span>private<span class="r">|</span>package<span class="r">]</span></code><a class="copiable-link" href="#index-fivar-visibility"> ¶</a></span>
</dt> <dd>
<p>Set the default instance variable visibility to the specified option so that instance variables declared outside the scope of any access modifier directives default to the specified visibility. </p> </dd> <dt>
<span><code class="code">-gen-decls</code><a class="copiable-link" href="#index-gen-decls"> ¶</a></span>
</dt> <dd>
<p>Dump interface declarations for all classes seen in the source file to a file named <samp class="file"><var class="var">sourcename</var>.decl</samp>. </p> </dd> <dt>
<span><code class="code">-Wassign-intercept <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wassign-intercept"> ¶</a></span>
</dt> <dd>
<p>Warn whenever an Objective-C assignment is being intercepted by the garbage collector. </p> </dd> <dt>
<span><code class="code">-Wno-property-assign-default <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wproperty-assign-default"> ¶</a></span>
</dt> <dd>
<p>Do not warn if a property for an Objective-C object has no assign semantics specified. </p> </dd> <dt>
<span><code class="code">-Wno-protocol <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wno-protocol"> ¶</a></span>
</dt> <dd>
<p>If a class is declared to implement a protocol, a warning is issued for every method in the protocol that is not implemented by the class. The default behavior is to issue a warning for every method not explicitly implemented in the class, even if a method implementation is inherited from the superclass. If you use the <samp class="option">-Wno-protocol</samp> option, then methods inherited from the superclass are considered to be implemented, and no warning is issued for them. </p> </dd> <dt>
<span><code class="code">-Wobjc-root-class <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wobjc-root-class"> ¶</a></span>
</dt> <dd>
<p>Warn if a class interface lacks a superclass. Most classes will inherit from <code class="code">NSObject</code> (or <code class="code">Object</code>) for example. When declaring classes intended to be root classes, the warning can be suppressed by marking their interfaces with <code class="code">__attribute__((objc_root_class))</code>. </p> </dd> <dt>
<span><code class="code">-Wselector <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wselector"> ¶</a></span>
</dt> <dd>
<p>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 <code class="code">@selector(…)</code> 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 <samp class="option">-fsyntax-only</samp> option is being used. </p> </dd> <dt>
<span><code class="code">-Wstrict-selector-match <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wstrict-selector-match"> ¶</a></span>
</dt> <dd>
<p>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 <code class="code">id</code> or <code class="code">Class</code>. When this flag is off (which is the default behavior), the compiler omits such warnings if any differences found are confined to types that share the same size and alignment. </p> </dd> <dt>
<span><code class="code">-Wundeclared-selector <span class="r">(Objective-C and Objective-C++ only)</span></code><a class="copiable-link" href="#index-Wundeclared-selector"> ¶</a></span>
</dt> <dd>
<p>Warn if a <code class="code">@selector(…)</code> expression referring to an undeclared selector is found. A selector is considered undeclared if no method with that name has been declared before the <code class="code">@selector(…)</code> expression, either explicitly in an <code class="code">@interface</code> or <code class="code">@protocol</code> declaration, or implicitly in an <code class="code">@implementation</code> section. This option always performs its checks as soon as a <code class="code">@selector(…)</code> expression is found, while <samp class="option">-Wselector</samp> 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. </p> </dd> <dt>
<span><code class="code">-print-objc-runtime-info</code><a class="copiable-link" href="#index-print-objc-runtime-info"> ¶</a></span>
</dt> <dd>
<p>Generate C header describing the largest structure that is passed by value, if any. </p> </dd> </dl> </div> <div class="nav-panel"> <p> Next: <a href="diagnostic-message-formatting-options">Options to Control Diagnostic Messages Formatting</a>, Previous: <a href="c_002b_002b-dialect-options">Options Controlling C++ Dialect</a>, Up: <a href="invoking-gcc">GCC Command Options</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
<p class="_attribution-p">
© Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Objective-C-and-Objective-C_002b_002b-Dialect-Options.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Objective-C-and-Objective-C_002b_002b-Dialect-Options.html</a>
</p>
</div>
|