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