]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/cppopts.texi
Update links to archived copy of SGI STL docs
[thirdparty/gcc.git] / gcc / doc / cppopts.texi
CommitLineData
85ec4feb 1@c Copyright (C) 1999-2018 Free Software Foundation, Inc.
40adaa27
NB
2@c This is part of the CPP and GCC manuals.
3@c For copying conditions, see the file gcc.texi.
4
5@c ---------------------------------------------------------------------
6@c Options affecting the preprocessor
7@c ---------------------------------------------------------------------
8
9@c If this file is included with the flag ``cppmanual'' set, it is
10@c formatted for inclusion in the CPP manual; otherwise the main GCC manual.
11
40adaa27
NB
12@item -D @var{name}
13@opindex D
14Predefine @var{name} as a macro, with definition @code{1}.
15
16@item -D @var{name}=@var{definition}
a09d4744
NB
17The contents of @var{definition} are tokenized and processed as if
18they appeared during translation phase three in a @samp{#define}
ec85a978 19directive. In particular, the definition is truncated by
a09d4744
NB
20embedded newline characters.
21
22If you are invoking the preprocessor from a shell or shell-like
23program you may need to use the shell's quoting syntax to protect
24characters such as spaces that have a meaning in the shell syntax.
40adaa27
NB
25
26If you wish to define a function-like macro on the command line, write
27its argument list with surrounding parentheses before the equals sign
ec85a978
SL
28(if any). Parentheses are meaningful to most shells, so you should
29quote the option. With @command{sh} and @command{csh},
40adaa27
NB
30@option{-D'@var{name}(@var{args@dots{}})=@var{definition}'} works.
31
32@option{-D} and @option{-U} options are processed in the order they
33are given on the command line. All @option{-imacros @var{file}} and
34@option{-include @var{file}} options are processed after all
35@option{-D} and @option{-U} options.
36
37@item -U @var{name}
38@opindex U
39Cancel any previous definition of @var{name}, either built in or
40provided with a @option{-D} option.
41
e4ff7948
SL
42@item -include @var{file}
43@opindex include
44Process @var{file} as if @code{#include "file"} appeared as the first
45line of the primary source file. However, the first directory searched
46for @var{file} is the preprocessor's working directory @emph{instead of}
47the directory containing the main source file. If not found there, it
48is searched for in the remainder of the @code{#include "@dots{}"} search
49chain as normal.
50
51If multiple @option{-include} options are given, the files are included
52in the order they appear on the command line.
53
54@item -imacros @var{file}
55@opindex imacros
56Exactly like @option{-include}, except that any output produced by
57scanning @var{file} is thrown away. Macros it defines remain defined.
58This allows you to acquire all the macros from a header without also
59processing its declarations.
60
61All files specified by @option{-imacros} are processed before all files
62specified by @option{-include}.
63
40adaa27
NB
64@item -undef
65@opindex undef
6e270179
NB
66Do not predefine any system-specific or GCC-specific macros. The
67standard predefined macros remain defined.
68@ifset cppmanual
79406520 69@xref{Standard Predefined Macros}.
6e270179 70@end ifset
40adaa27 71
c71b316b
SL
72@item -pthread
73@opindex pthread
74Define additional macros required for using the POSIX threads library.
75You should use this option consistently for both compilation and linking.
76This option is supported on GNU/Linux targets, most other Unix derivatives,
77and also on x86 Cygwin and MinGW targets.
78
40adaa27
NB
79@item -M
80@opindex M
ab940b73
RW
81@cindex @command{make}
82@cindex dependencies, @command{make}
40adaa27
NB
83Instead of outputting the result of preprocessing, output a rule
84suitable for @command{make} describing the dependencies of the main
85source file. The preprocessor outputs one @command{make} rule containing
86the object file name for that source file, a colon, and the names of all
87the included files, including those coming from @option{-include} or
4460b2dc 88@option{-imacros} command-line options.
40adaa27
NB
89
90Unless specified explicitly (with @option{-MT} or @option{-MQ}), the
78392049
TT
91object file name consists of the name of the source file with any
92suffix replaced with object file suffix and with any leading directory
93parts removed. If there are many included files then the rule is
94split into several lines using @samp{\}-newline. The rule has no
95commands.
40adaa27
NB
96
97This option does not suppress the preprocessor's debug output, such as
98@option{-dM}. To avoid mixing such debug output with the dependency
99rules you should explicitly specify the dependency output file with
100@option{-MF}, or use an environment variable like
caba570b 101@env{DEPENDENCIES_OUTPUT} (@pxref{Environment Variables}). Debug output
ec85a978 102is still sent to the regular output stream as normal.
40adaa27 103
49e7b251
NB
104Passing @option{-M} to the driver implies @option{-E}, and suppresses
105warnings with an implicit @option{-w}.
40adaa27
NB
106
107@item -MM
108@opindex MM
109Like @option{-M} but do not mention header files that are found in
110system header directories, nor header files that are included,
111directly or indirectly, from such a header.
112
113This implies that the choice of angle brackets or double quotes in an
114@samp{#include} directive does not in itself determine whether that
ec85a978 115header appears in @option{-MM} dependency output.
40adaa27 116
5560a945 117@anchor{dashMF}
40adaa27
NB
118@item -MF @var{file}
119@opindex MF
40adaa27
NB
120When used with @option{-M} or @option{-MM}, specifies a
121file to write the dependencies to. If no @option{-MF} switch is given
ec85a978 122the preprocessor sends the rules to the same place it would send
40adaa27
NB
123preprocessed output.
124
125When used with the driver options @option{-MD} or @option{-MMD},
126@option{-MF} overrides the default dependency output file.
127
e72c4afd
BK
128If @var{file} is @file{-}, then the dependencies are written to @file{stdout}.
129
40adaa27
NB
130@item -MG
131@opindex MG
3f8ffc7c
RS
132In conjunction with an option such as @option{-M} requesting
133dependency generation, @option{-MG} assumes missing header files are
134generated files and adds them to the dependency list without raising
135an error. The dependency filename is taken directly from the
136@code{#include} directive without prepending any path. @option{-MG}
137also suppresses preprocessed output, as a missing header file renders
138this useless.
40adaa27
NB
139
140This feature is used in automatic updating of makefiles.
141
142@item -MP
143@opindex MP
144This option instructs CPP to add a phony target for each dependency
145other than the main file, causing each to depend on nothing. These
146dummy rules work around errors @command{make} gives if you remove header
147files without updating the @file{Makefile} to match.
148
149This is typical output:
150
3ab51846 151@smallexample
40adaa27
NB
152test.o: test.c test.h
153
154test.h:
3ab51846 155@end smallexample
40adaa27
NB
156
157@item -MT @var{target}
158@opindex MT
159
160Change the target of the rule emitted by dependency generation. By
78392049
TT
161default CPP takes the name of the main input file, deletes any
162directory components and any file suffix such as @samp{.c}, and
163appends the platform's usual object suffix. The result is the target.
40adaa27 164
ec85a978 165An @option{-MT} option sets the target to be exactly the string you
40adaa27
NB
166specify. If you want multiple targets, you can specify them as a single
167argument to @option{-MT}, or use multiple @option{-MT} options.
168
169For example, @option{@w{-MT '$(objpfx)foo.o'}} might give
170
3ab51846 171@smallexample
40adaa27 172$(objpfx)foo.o: foo.c
3ab51846 173@end smallexample
40adaa27
NB
174
175@item -MQ @var{target}
176@opindex MQ
177
178Same as @option{-MT}, but it quotes any characters which are special to
179Make. @option{@w{-MQ '$(objpfx)foo.o'}} gives
180
3ab51846 181@smallexample
40adaa27 182$$(objpfx)foo.o: foo.c
3ab51846 183@end smallexample
40adaa27
NB
184
185The default target is automatically quoted, as if it were given with
186@option{-MQ}.
187
188@item -MD
189@opindex MD
190@option{-MD} is equivalent to @option{-M -MF @var{file}}, except that
191@option{-E} is not implied. The driver determines @var{file} based on
192whether an @option{-o} option is given. If it is, the driver uses its
78392049
TT
193argument but with a suffix of @file{.d}, otherwise it takes the name
194of the input file, removes any directory components and suffix, and
195applies a @file{.d} suffix.
40adaa27
NB
196
197If @option{-MD} is used in conjunction with @option{-E}, any
198@option{-o} switch is understood to specify the dependency output file
e8c96d09 199(@pxref{dashMF,,-MF}), but if used without @option{-E}, each @option{-o}
40adaa27
NB
200is understood to specify a target object file.
201
202Since @option{-E} is not implied, @option{-MD} can be used to generate
203a dependency output file as a side-effect of the compilation process.
204
205@item -MMD
206@opindex MMD
207Like @option{-MD} except mention only user header files, not system
78466c0e 208header files.
40adaa27 209
e4ff7948
SL
210@item -fpreprocessed
211@opindex fpreprocessed
212Indicate to the preprocessor that the input file has already been
213preprocessed. This suppresses things like macro expansion, trigraph
214conversion, escaped newline splicing, and processing of most directives.
215The preprocessor still recognizes and removes comments, so that you can
216pass a file preprocessed with @option{-C} to the compiler without
217problems. In this mode the integrated preprocessor is little more than
218a tokenizer for the front ends.
c0d578e6 219
e4ff7948
SL
220@option{-fpreprocessed} is implicit if the input file has one of the
221extensions @samp{.i}, @samp{.ii} or @samp{.mi}. These are the
222extensions that GCC uses for preprocessed files created by
c0d578e6
GK
223@option{-save-temps}.
224
ccfc4c91
OW
225@item -fdirectives-only
226@opindex fdirectives-only
227When preprocessing, handle directives, but do not expand macros.
228
229The option's behavior depends on the @option{-E} and @option{-fpreprocessed}
230options.
231
232With @option{-E}, preprocessing is limited to the handling of directives
233such as @code{#define}, @code{#ifdef}, and @code{#error}. Other
234preprocessor operations, such as macro expansion and trigraph
235conversion are not performed. In addition, the @option{-dD} option is
236implicitly enabled.
237
238With @option{-fpreprocessed}, predefinition of command line and most
239builtin macros is disabled. Macros such as @code{__LINE__}, which are
240contextually dependent, are handled normally. This enables compilation of
241files previously preprocessed with @code{-E -fdirectives-only}.
242
243With both @option{-E} and @option{-fpreprocessed}, the rules for
244@option{-fpreprocessed} take precedence. This enables full preprocessing of
245files previously preprocessed with @code{-E -fdirectives-only}.
246
b1822ccc
NB
247@item -fdollars-in-identifiers
248@opindex fdollars-in-identifiers
249@anchor{fdollars-in-identifiers}
250Accept @samp{$} in identifiers.
251@ifset cppmanual
6ccde948 252@xref{Identifier characters}.
b1822ccc
NB
253@end ifset
254
af15a2fe
JM
255@item -fextended-identifiers
256@opindex fextended-identifiers
257Accept universal character names in identifiers. This option is
701cade1 258enabled by default for C99 (and later C standard versions) and C++.
af15a2fe 259
5dc99c46
SB
260@item -fno-canonical-system-headers
261@opindex fno-canonical-system-headers
262When preprocessing, do not shorten system header paths with canonicalization.
263
40adaa27
NB
264@item -ftabstop=@var{width}
265@opindex ftabstop
266Set the distance between tab stops. This helps the preprocessor report
267correct column numbers in warnings or errors, even if tabs appear on the
268line. If the value is less than 1 or greater than 100, the option is
269ignored. The default is 8.
270
92582b75
TT
271@item -ftrack-macro-expansion@r{[}=@var{level}@r{]}
272@opindex ftrack-macro-expansion
273Track locations of tokens across macro expansions. This allows the
274compiler to emit diagnostic about the current macro expansion stack
275when a compilation error occurs in a macro expansion. Using this
276option makes the preprocessor and the compiler consume more
277memory. The @var{level} parameter can be used to choose the level of
278precision of token location tracking thus decreasing the memory
279consumption if necessary. Value @samp{0} of @var{level} de-activates
ec85a978 280this option. Value @samp{1} tracks tokens locations in a
92582b75
TT
281degraded mode for the sake of minimal memory overhead. In this mode
282all tokens resulting from the expansion of an argument of a
283function-like macro have the same location. Value @samp{2} tracks
284tokens locations completely. This value is the most memory hungry.
285When this option is given no argument, the default parameter value is
286@samp{2}.
287
5f05dc55 288Note that @code{-ftrack-macro-expansion=2} is activated by default.
51fce2d3 289
7365279f
BK
290@item -fmacro-prefix-map=@var{old}=@var{new}
291@opindex fmacro-prefix-map
292When preprocessing files residing in directory @file{@var{old}},
293expand the @code{__FILE__} and @code{__BASE_FILE__} macros as if the
294files resided in directory @file{@var{new}} instead. This can be used
295to change an absolute path to a relative path by using @file{.} for
296@var{new} which can result in more reproducible builds that are
297location independent. This option also affects
298@code{__builtin_FILE()} during compilation. See also
299@option{-ffile-prefix-map}.
300
e6cc3a24
ZW
301@item -fexec-charset=@var{charset}
302@opindex fexec-charset
50668cf6 303@cindex character set, execution
e6cc3a24
ZW
304Set the execution character set, used for string and character
305constants. The default is UTF-8. @var{charset} can be any encoding
306supported by the system's @code{iconv} library routine.
307
308@item -fwide-exec-charset=@var{charset}
309@opindex fwide-exec-charset
50668cf6 310@cindex character set, wide execution
e6cc3a24
ZW
311Set the wide execution character set, used for wide string and
312character constants. The default is UTF-32 or UTF-16, whichever
313corresponds to the width of @code{wchar_t}. As with
bc4c01b7 314@option{-fexec-charset}, @var{charset} can be any encoding supported
e6cc3a24
ZW
315by the system's @code{iconv} library routine; however, you will have
316problems with encodings that do not fit exactly in @code{wchar_t}.
317
16dd5cfe
EC
318@item -finput-charset=@var{charset}
319@opindex finput-charset
50668cf6 320@cindex character set, input
16dd5cfe 321Set the input character set, used for translation from the character
8a36672b 322set of the input file to the source character set used by GCC@. If the
16dd5cfe 323locale does not specify, or GCC cannot get this information from the
8a36672b 324locale, the default is UTF-8. This can be overridden by either the locale
4460b2dc 325or this command-line option. Currently the command-line option takes
8a36672b 326precedence if there's a conflict. @var{charset} can be any encoding
16dd5cfe
EC
327supported by the system's @code{iconv} library routine.
328
e4ff7948
SL
329@ifclear cppmanual
330@item -fpch-deps
331@opindex fpch-deps
332When using precompiled headers (@pxref{Precompiled Headers}), this flag
ec85a978
SL
333causes the dependency-output flags to also list the files from the
334precompiled header's dependencies. If not specified, only the
335precompiled header are listed and not the files that were used to
336create it, because those files are not consulted when a precompiled
e4ff7948
SL
337header is used.
338
339@item -fpch-preprocess
340@opindex fpch-preprocess
341This option allows use of a precompiled header (@pxref{Precompiled
342Headers}) together with @option{-E}. It inserts a special @code{#pragma},
343@code{#pragma GCC pch_preprocess "@var{filename}"} in the output to mark
344the place where the precompiled header was found, and its @var{filename}.
345When @option{-fpreprocessed} is in use, GCC recognizes this @code{#pragma}
346and loads the PCH@.
347
348This option is off by default, because the resulting preprocessed output
349is only really suitable as input to GCC@. It is switched on by
350@option{-save-temps}.
351
352You should not write this @code{#pragma} in your own code, but it is
353safe to edit the filename if the PCH file is available in a different
354location. The filename may be absolute or it may be relative to GCC's
355current directory.
356@end ifclear
357
b20d9f0c
AO
358@item -fworking-directory
359@opindex fworking-directory
360@opindex fno-working-directory
ec85a978 361Enable generation of linemarkers in the preprocessor output that
b20d9f0c 362let the compiler know the current working directory at the time of
ec85a978
SL
363preprocessing. When this option is enabled, the preprocessor
364emits, after the initial linemarker, a second linemarker with the
365current working directory followed by two slashes. GCC uses this
b20d9f0c
AO
366directory, when it's present in the preprocessed input, as the
367directory emitted as the current working directory in some debugging
368information formats. This option is implicitly enabled if debugging
369information is enabled, but this can be inhibited with the negated
370form @option{-fno-working-directory}. If the @option{-P} flag is
371present in the command line, this option has no effect, since no
372@code{#line} directives are emitted whatsoever.
373
40adaa27
NB
374@item -A @var{predicate}=@var{answer}
375@opindex A
376Make an assertion with the predicate @var{predicate} and answer
377@var{answer}. This form is preferred to the older form @option{-A
378@var{predicate}(@var{answer})}, which is still supported, because
379it does not use shell special characters.
380@ifset cppmanual
899015a0 381@xref{Obsolete Features}.
40adaa27
NB
382@end ifset
383
384@item -A -@var{predicate}=@var{answer}
385Cancel an assertion with the predicate @var{predicate} and answer
386@var{answer}.
387
40adaa27
NB
388@item -C
389@opindex C
390Do not discard comments. All comments are passed through to the output
391file, except for comments in processed directives, which are deleted
392along with the directive.
393
394You should be prepared for side effects when using @option{-C}; it
395causes the preprocessor to treat comments as tokens in their own right.
396For example, comments appearing at the start of what would be a
397directive line have the effect of turning that line into an ordinary
398source line, since the first token on the line is no longer a @samp{#}.
399
477cdac7 400@item -CC
ec85a978 401@opindex CC
477cdac7
JT
402Do not discard comments, including during macro expansion. This is
403like @option{-C}, except that comments contained within macros are
404also passed through to the output file where the macro is expanded.
405
406In addition to the side-effects of the @option{-C} option, the
407@option{-CC} option causes all C++-style comments inside a macro
408to be converted to C-style comments. This is to prevent later use
9a376494 409of that macro from inadvertently commenting out the remainder of
477cdac7
JT
410the source line.
411
412The @option{-CC} option is generally used to support lint comments.
413
e4ff7948
SL
414@item -P
415@opindex P
416Inhibit generation of linemarkers in the output from the preprocessor.
417This might be useful when running the preprocessor on something that is
418not C code, and will be sent to a program which might be confused by the
419linemarkers.
420@ifset cppmanual
421@xref{Preprocessor Output}.
422@end ifset
423
71585576
SL
424@cindex traditional C language
425@cindex C language, traditional
426@item -traditional
427@itemx -traditional-cpp
b6fb43ab 428@opindex traditional-cpp
71585576
SL
429@opindex traditional
430
431Try to imitate the behavior of pre-standard C preprocessors, as
b6fb43ab 432opposed to ISO C preprocessors.
40adaa27
NB
433@ifset cppmanual
434@xref{Traditional Mode}.
435@end ifset
71585576
SL
436@ifclear cppmanual
437See the GNU CPP manual for details.
438@end ifclear
439
440Note that GCC does not otherwise attempt to emulate a pre-standard
441C compiler, and these options are only supported with the @option{-E}
442switch, or when invoking CPP explicitly.
40adaa27
NB
443
444@item -trigraphs
445@opindex trigraphs
71585576 446Support ISO C trigraphs.
40adaa27
NB
447These are three-character sequences, all starting with @samp{??}, that
448are defined by ISO C to stand for single characters. For example,
449@samp{??/} stands for @samp{\}, so @samp{'??/n'} is a character
71585576
SL
450constant for a newline.
451@ifset cppmanual
452@xref{Initial processing}.
453@end ifset
40adaa27 454
71585576 455@ifclear cppmanual
40adaa27
NB
456The nine trigraphs and their replacements are
457
478c9e72 458@smallexample
40adaa27
NB
459Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
460Replacement: [ ] @{ @} # \ ^ | ~
478c9e72 461@end smallexample
40adaa27
NB
462@end ifclear
463
71585576
SL
464By default, GCC ignores trigraphs, but in
465standard-conforming modes it converts them. See the @option{-std} and
466@option{-ansi} options.
467
40adaa27
NB
468@item -remap
469@opindex remap
470Enable special code to work around file systems which only permit very
471short file names, such as MS-DOS@.
472
40adaa27
NB
473@item -H
474@opindex H
475Print the name of each header file used, in addition to other normal
476activities. Each name is indented to show how deep in the
79406520
GK
477@samp{#include} stack it is. Precompiled header files are also
478printed, even if they are found to be invalid; an invalid precompiled
479header file is printed with @samp{...x} and a valid one with @samp{...!} .
40adaa27 480
c3e50bc4
SL
481@item -d@var{letters}
482@opindex d
483Says to make debugging dumps during compilation as specified by
484@var{letters}. The flags documented here are those relevant to the
485preprocessor. Other @var{letters} are interpreted
e4ff7948 486by the compiler proper, or reserved for future versions of GCC, and so
c3e50bc4 487are silently ignored. If you specify @var{letters} whose behavior
e4ff7948 488conflicts, the result is undefined.
c3e50bc4
SL
489@ifclear cppmanual
490@xref{Developer Options}, for more information.
491@end ifclear
e4ff7948 492
c3e50bc4
SL
493@table @gcctabopt
494@item -dM
e4ff7948
SL
495@opindex dM
496Instead of the normal output, generate a list of @samp{#define}
497directives for all the macros defined during the execution of the
498preprocessor, including predefined macros. This gives you a way of
499finding out what is predefined in your version of the preprocessor.
500Assuming you have no file @file{foo.h}, the command
501
502@smallexample
503touch foo.h; cpp -dM foo.h
504@end smallexample
505
506@noindent
ec85a978 507shows all the predefined macros.
e4ff7948
SL
508
509@ifclear cppmanual
510If you use @option{-dM} without the @option{-E} option, @option{-dM} is
511interpreted as a synonym for @option{-fdump-rtl-mach}.
512@xref{Developer Options, , ,gcc}.
513@end ifclear
514
c3e50bc4 515@item -dD
e4ff7948 516@opindex dD
c3e50bc4 517Like @option{-dM} except in two respects: it does @emph{not} include the
e4ff7948
SL
518predefined macros, and it outputs @emph{both} the @samp{#define}
519directives and the result of preprocessing. Both kinds of output go to
520the standard output file.
521
c3e50bc4 522@item -dN
e4ff7948 523@opindex dN
c3e50bc4 524Like @option{-dD}, but emit only the macro names, not their expansions.
e4ff7948 525
c3e50bc4 526@item -dI
e4ff7948
SL
527@opindex dI
528Output @samp{#include} directives in addition to the result of
529preprocessing.
530
c3e50bc4 531@item -dU
e4ff7948 532@opindex dU
c3e50bc4 533Like @option{-dD} except that only macros that are expanded, or whose
e4ff7948
SL
534definedness is tested in preprocessor directives, are output; the
535output is delayed until the use or test of the macro; and
536@samp{#undef} directives are also output for macros tested but
537undefined at the time.
538@end table
539
540@item -fdebug-cpp
541@opindex fdebug-cpp
ec85a978
SL
542This option is only useful for debugging GCC. When used from CPP or with
543@option{-E}, it dumps debugging information about location maps. Every
e4ff7948 544token in the output is preceded by the dump of the map its location
ec85a978 545belongs to.
e4ff7948 546
ec85a978 547When used from GCC without @option{-E}, this option has no effect.