]> git.ipfire.org Git - thirdparty/gcc.git/blame - doc/cppdiropts.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / doc / cppdiropts.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. option:: -I {dir}, -iquote {dir}, -isystem {dir}, -idirafter {dir}
7
8 Add the directory :samp:`{dir}` to the list of directories to be searched
9 for header files during preprocessing.
10
11 .. only:: cpp
12
13 See :ref:`search-path`.
14
15 If :samp:`{dir}` begins with :samp:`=` or ``$SYSROOT``, then the :samp:`=`
16 or ``$SYSROOT`` is replaced by the sysroot prefix; see
17 :option:`--sysroot` and :option:`-isysroot`.
18
19 Directories specified with :option:`-iquote` apply only to the quote
20 form of the directive, ``#include "file"``.
21 Directories specified with :option:`-I`, :option:`-isystem`,
22 or :option:`-idirafter` apply to lookup for both the
23 ``#include "file"`` and
24 ``#include <file>`` directives.
25
26 You can specify any number or combination of these options on the
27 command line to search for header files in several directories.
28 The lookup order is as follows:
29
30 * For the quote form of the include directive, the directory of the current
31 file is searched first.
32
33 * For the quote form of the include directive, the directories specified
34 by :option:`-iquote` options are searched in left-to-right order,
35 as they appear on the command line.
36
37 * Directories specified with :option:`-I` options are scanned in
38 left-to-right order.
39
40 * Directories specified with :option:`-isystem` options are scanned in
41 left-to-right order.
42
43 * Standard system directories are scanned.
44
45 * Directories specified with :option:`-idirafter` options are scanned in
46 left-to-right order.
47
48 You can use :option:`-I` to override a system header
49 file, substituting your own version, since these directories are
50 searched before the standard system header file directories.
51 However, you should
52 not use this option to add directories that contain vendor-supplied
53 system header files; use :option:`-isystem` for that.
54
55 The :option:`-isystem` and :option:`-idirafter` options also mark the directory
56 as a system directory, so that it gets the same special treatment that
57 is applied to the standard system directories.
58
59 .. only:: cpp
60
61 See :ref:`system-headers`.
62
63
64 If a standard system include directory, or a directory specified with
65 :option:`-isystem`, is also specified with :option:`-I`, the :option:`-I`
66 option is ignored. The directory is still searched but as a
67 system directory at its normal position in the system include chain.
68 This is to ensure that GCC's procedure to fix buggy system headers and
69 the ordering for the ``#include_next`` directive are not inadvertently
70 changed.
71 If you really need to change the search order for system directories,
72 use the :option:`-nostdinc` and/or :option:`-isystem` options.
73
74 .. only:: cpp
75
76 See :ref:`system-headers`.
77
78
79.. option:: -I-
80
81 Split the include path.
82 This option has been deprecated. Please use :option:`-iquote` instead for
83 :option:`-I` directories before the :option:`-I-` and remove the :option:`-I-`
84 option.
85
86 Any directories specified with :option:`-I`
87 options before :option:`-I-` are searched only for headers requested with
88 ``#include "file"`` ; they are not searched for
89 ``#include <file>``. If additional directories are
90 specified with :option:`-I` options after the :option:`-I-`, those
91 directories are searched for all :samp:`#include` directives.
92
93 In addition, :option:`-I-` inhibits the use of the directory of the current
94 file directory as the first search directory for ``#include
95 "file"``. There is no way to override this effect of :option:`-I-`.
96
97 .. only:: cpp
98
99 See :ref:`search-path`.
100
101
102.. option:: -iprefix {prefix}
103
104 Specify :samp:`{prefix}` as the prefix for subsequent :option:`-iwithprefix`
105 options. If the prefix represents a directory, you should include the
106 final :samp:`/`.
107
108.. option:: -iwithprefix {dir}, -iwithprefixbefore {dir}
109
110 Append :samp:`{dir}` to the prefix specified previously with
111 :option:`-iprefix`, and add the resulting directory to the include search
112 path. :option:`-iwithprefixbefore` puts it in the same place :option:`-I`
113 would; :option:`-iwithprefix` puts it where :option:`-idirafter` would.
114
115.. option:: -isysroot {dir}
116
117 This option is like the :option:`--sysroot` option, but applies only to
118 header files (except for Darwin targets, where it applies to both header
119 files and libraries). See the :option:`--sysroot` option for more
120 information.
121
122.. option:: -imultilib {dir}
123
124 Use :samp:`{dir}` as a subdirectory of the directory containing
125 target-specific C++ headers.
126
127.. option:: -nostdinc
128
129 Do not search the standard system directories for header files.
130 Only the directories explicitly specified with :option:`-I`,
131 :option:`-iquote`, :option:`-isystem`, and/or :option:`-idirafter`
132 options (and the directory of the current file, if appropriate)
133 are searched.
134
135.. option:: -nostdinc++
136
137 Do not search for header files in the C++-specific standard directories,
138 but do still search the other standard directories. (This option is
139 used when building the C++ library.)
140
141.. option:: -Wcomment, -Wcomments
142
143 Warn whenever a comment-start sequence :samp:`/*` appears in a :samp:`/*`
144 comment, or whenever a backslash-newline appears in a :samp:`//` comment.
145 This warning is enabled by :option:`-Wall`.
146
147.. option:: -Wtrigraphs
148
149.. _wtrigraphs:
150
151 Warn if any trigraphs are encountered that might change the meaning of
152 the program. Trigraphs within comments are not warned about,
153 except those that would form escaped newlines.
154
155 This option is implied by :option:`-Wall`. If :option:`-Wall` is not
156 given, this option is still enabled unless trigraphs are enabled. To
157 get trigraph conversion without warnings, but get the other
158 :option:`-Wall` warnings, use :samp:`-trigraphs -Wall -Wno-trigraphs`.
159
160.. option:: -Wundef
161
162 Warn if an undefined identifier is evaluated in an ``#if`` directive.
163 Such identifiers are replaced with zero.
164
165.. option:: -Wno-undef
166
167 Default setting; overrides :option:`-Wundef`.
168
169.. option:: -Wexpansion-to-defined
170
171 Warn whenever :samp:`defined` is encountered in the expansion of a macro
172 (including the case where the macro is expanded by an :samp:`#if` directive).
173 Such usage is not portable.
174 This warning is also enabled by :option:`-Wpedantic` and :option:`-Wextra`.
175
176.. option:: -Wunused-macros
177
178 Warn about macros defined in the main file that are unused. A macro
179 is :dfn:`used` if it is expanded or tested for existence at least once.
180 The preprocessor also warns if the macro has not been used at the
181 time it is redefined or undefined.
182
183 Built-in macros, macros defined on the command line, and macros
184 defined in include files are not warned about.
185
186 .. note::
187
188 If a macro is actually used, but only used in skipped
189 conditional blocks, then the preprocessor reports it as unused. To avoid the
190 warning in such a case, you might improve the scope of the macro's
191 definition by, for example, moving it into the first skipped block.
192 Alternatively, you could provide a dummy use with something like:
193
194 .. code-block:: c++
195
196 #if defined the_macro_causing_the_warning
197 #endif
198
199.. option:: -Wno-endif-labels
200
201 Do not warn whenever an ``#else`` or an ``#endif`` are followed by text.
202 This sometimes happens in older programs with code of the form
203
204 .. code-block:: c++
205
206 #if FOO
207 ...
208 #else FOO
209 ...
210 #endif FOO
211
212 The second and third ``FOO`` should be in comments.
213 This warning is on by default.
214
215.. option:: -Wendif-labels
216
3ed1b4ce 217 Default setting; overrides :option:`-Wno-endif-labels`.