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