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