CPP(1)

๐Ÿ“ฆ version 15.2.0, in ubuntu questing

๐Ÿ’– cpp: manual page, section 1, from GNU ๐Ÿ’–

๐ŸŒธ NAME ๐ŸŒธ

cpp - The C Preprocessor โœจ

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

cpp [-Dmacro[=defn]...] [-Umacro]
    [-Idir...] [-iquotedir...]
    [-M|-MM] [-MG] [-MF filename]
    [-MP] [-MQ target...]
    [-MT target...]
    infile [[-o] outfile]

okay so this is the quick glance version ๐Ÿ‘€ Only the most useful options are up there, bestie. For a more complete list of preprocessor-specific options, check below. Also, cpp takes most gcc driver options too, which I'm not listing here, so go to the GCC documentation if you need those details ๐Ÿ’…

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

The C preprocessor, aka cpp, is a macro processor ๐Ÿงš The C compiler uses it automatically to transform your program before compilation. It's called a macro processor because it lets you define macros, which are short abbreviations for longer constructs. Iconic behavior, honestly ๐Ÿ‘‘

The C preprocessor is meant to be used only with C, C++, and Objective-C source code. In the past, people have abused it as a general text processor ๐Ÿ˜ญ It will choke on input that doesn't follow C's lexical rules. For example, apostrophes get treated as the start of character constants, and that causes errors ๐Ÿ’€ You also can't count on it keeping the characteristics of your input that don't matter to C-family languages. If you preprocess a Makefile, all the hard tabs get removed, and the Makefile won't work anymore. Not me being shocked ๐Ÿ™ˆ

Having said that, you can lowkey get away with using cpp on things that aren't C. Other Algol-ish languages are usually safe (Ada, etc.) Assembly is also fine, but be careful ๐ŸŒˆ -traditional-cpp mode preserves more white space and is otherwise more permissive โœจ Most of the problems can be dodged by writing C or C++ style comments instead of native language comments, and by keeping your macros simple ๐Ÿซถ

Whenever you can, use a preprocessor that's built for the language you're writing in ๐Ÿ’œ Modern versions of the GNU assembler have macro facilities. Most high level programming languages have their own conditional compilation and inclusion mechanism. And if all else fails, try a true general text processor, like GNU M4. Main character energy for real ๐ŸŽ€

C preprocessors vary in some details. This manual covers the GNU C preprocessor, which gives you a small superset of the features of ISO Standard C. In its default mode, the GNU C preprocessor skips a few things the standard requires. These are features that are rarely, if ever, used, but they can cause surprising changes to the meaning of a program that doesn't expect them ๐Ÿ™ˆ If you want strict ISO Standard C, use -std=c90, -std=c99, -std=c11 or -std=c17, depending on which version of the standard you want. To get all the mandatory diagnostics, you also have to use -pedantic ๐Ÿ”ฅ

This manual describes the behavior of the ISO preprocessor. To cut down on gratuitous differences, wherever the ISO preprocessor's behavior doesn't clash with traditional semantics, the traditional preprocessor should act the same way. The differences that do exist are detailed in the section Traditional Mode ๐Ÿฆ‹

For clarity, unless noted otherwise, any mention of CPP in this manual means GNU CPP ๐Ÿ’–


โœจ OPTIONS โœจ

Okay so the cpp command expects two file names as arguments: infile and outfile. The preprocessor reads infile, along with any other files it pulls in with #include. All the output from the combined input files gets written to outfile ๐Ÿ“

Either infile or outfile can be -. As infile, it means read from standard input. As outfile, it means write to standard output ๐ŸŒธ If either file is left out, it works the same as if - had been given for that file. You can also use the -o outfile option to specify the output file ๐ŸŽ€

Unless noted otherwise, or unless the option ends in =, every option that takes an argument can have that argument right after the option, or with a space between the option and the argument. -Ifoo and -I foo do the exact same thing ๐Ÿ’…

Lots of options have multi-letter names, so you can't group multiple single-letter options together. -dM is very different from -d -M ๐Ÿ˜ญ

  • -D name โ€” Predefines name as a macro, with the definition 1 ๐Ÿงš
  • -D name=definition โ€” The contents of definition get tokenized and processed as if they showed up during translation phase three in a #define directive. Specifically, the definition gets cut off at any embedded newline characters โœ‚๏ธ

If you're running the preprocessor from a shell or shell-like program, you might need the shell's quoting syntax to protect characters like spaces, since those mean something in shell syntax ๐Ÿš

Want to define a function-like macro on the command line? Write its argument list in surrounding parentheses before the equals sign (if there is one). Parentheses mean something to most shells, so make sure you quote the option. With sh and csh, -D'name(args...)=definition' works ๐Ÿ’–

-D and -U options get processed in the order they're given on the command line. All -imacros file and -include file options get processed after all the -D and -U options ๐ŸŒˆ

  • -U name โ€” Cancels any previous definition of name, whether it was built in or provided with a -D option ๐Ÿงน
  • -include file โ€” Processes file as if #include "file" appeared as the first line of the primary source file. Here's the twist though: the first directory searched for file is the preprocessor's working directory, not the directory containing the main source file. If it's not found there, it gets searched for in the rest of the #include "..." search chain, like normal ๐Ÿ”

If you give multiple -include options, the files get included in the order they show up on the command line ๐Ÿ“š

  • -imacros file โ€” Exactly like -include, except any output produced by scanning file gets thrown away. The macros it defines stay defined. This lets you grab all the macros from a header without also processing its declarations ๐Ÿซง

Every file specified by -imacros gets processed before every file specified by -include ๐Ÿ’œ

  • -undef โ€” Don't predefine any system-specific or GCC-specific macros. The standard predefined macros stay defined ๐Ÿ™…โ€โ™€๏ธ
  • -pthread โ€” Defines additional macros needed for using the POSIX threads library. Use this option consistently for both compilation and linking ๐Ÿงต It's supported on GNU/Linux targets, most other Unix derivatives, and also on x86 Cygwin and MinGW targets ๐ŸŒธ
  • -M โ€” Instead of outputting the result of preprocessing, this outputs a rule suitable for make that describes the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files. That includes files coming from -include or -imacros command-line options ๐Ÿ”—

Unless you set it explicitly (with -MT or -MQ), the object file name is the source file name with any suffix swapped for the object file suffix, and with any leading directory parts removed ๐Ÿ“ฆ If there are a lot of included files, the rule gets split across several lines using \-newline. The rule has no commands ๐Ÿ’…

This option does not suppress the preprocessor's debug output, like -dM. To avoid mixing that debug output with the dependency rules, you should explicitly specify the dependency output file with -MF, or use an environment variable like DEPENDENCIES_OUTPUT. Debug output still goes to the regular output stream like normal ๐Ÿ™ˆ

Passing -M to the driver implies -E, and suppresses warnings with an implicit -w ๐Ÿคซ

  • -MM โ€” Like -M, but doesn't mention header files found in system header directories, or header files included, directly or indirectly, from one of those headers ๐ŸŒฟ

This means the choice of angle brackets or double quotes in an #include directive doesn't, on its own, decide whether that header shows up in -MM dependency output ๐ŸŽ€

  • -MF file โ€” When used with -M or -MM, this specifies a file to write the dependencies to. If you don't give a -MF switch, the preprocessor sends the rules to the same place it would send preprocessed output ๐Ÿ“ฌ

When used with the driver options -MD or -MMD, -MF overrides the default dependency output file ๐Ÿซถ

If file is -, the dependencies get written to stdout โœจ

  • -MG โ€” Used together with an option like -M that requests dependency generation. -MG assumes missing header files are generated files, and adds them to the dependency list without raising an error. The dependency filename is taken directly from the #include directive, without prepending any path ๐Ÿงฉ -MG also suppresses preprocessed output, since a missing header file makes that useless ๐Ÿ™ƒ

This feature is used in automatic updating of makefiles ๐Ÿ› ๏ธ

  • -Mno-modules โ€” Disables dependency generation for compiled module interfaces ๐Ÿšซ
  • -MP โ€” This tells CPP to add a phony target for each dependency other than the main file, so that each one depends on nothing. These dummy rules work around errors that make gives if you remove header files without updating the Makefile to match ๐Ÿฆ‹

Typical output looks like this:

test.o: test.c test.h

test.h:
  • -MT target โ€” Changes the target of the rule emitted by dependency generation. By default, CPP takes the name of the main input file, deletes any directory components and any file suffix like .c, and appends the platform's usual object suffix. That result is the target ๐ŸŽฏ

An -MT option sets the target to be exactly the string you specify. If you want multiple targets, you can give them as a single argument to -MT, or use multiple -MT options ๐ŸŒˆ

For example, -MT '$(objpfx)foo.o' might give:

$(objpfx)foo.o: foo.c
  • -MQ target โ€” Same as -MT, but it quotes any characters that are special to Make ๐Ÿ”ฎ -MQ '$(objpfx)foo.o' gives:
$$(objpfx)foo.o: foo.c

The default target is automatically quoted, as if it had been given with -MQ ๐Ÿ’…

  • -MD โ€” -MD is equivalent to -M -MF file, except that -E is not implied. The driver figures out file based on whether an -o option is given. If it is, the driver uses its argument but with a suffix of .d. Otherwise, it takes the name of the input file, removes any directory components and suffix, and applies a .d suffix ๐Ÿ“

If -MD is used together with -E, any -o switch is understood to specify the dependency output file. But if it's used without -E, each -o is understood to specify a target object file ๐ŸŽ€

Since -E is not implied, -MD can generate a dependency output file as a side effect of the compilation process. Multitasking queen behavior ๐Ÿ‘‘

  • -MMD โ€” Same deal as -MD, but bestie, it only mentions your own user header files and skips the system ones ๐Ÿงš
  • -fpreprocessed โ€” This tells the preprocessor that your input has already been preprocessed โœจ So it skips macro expansion, trigraph conversion, escaped newline splicing, and most directives. It still removes comments though, so you can pass along a file made with -C to the compiler with zero drama. In this mode the integrated preprocessor is basically just a tokenizer for the front ends ๐Ÿ’…
    • It's switched on automatically if your input file ends in .i, .ii or .mi. Those are the extensions GCC uses for preprocessed files made by -save-temps ๐Ÿฆ‹
  • -fdirectives-only โ€” When preprocessing, it handles directives but does not expand macros ๐ŸŒธ How it acts depends on -E and -fpreprocessed:
    • With -E, preprocessing is limited to directives like "#define", "#ifdef", and "#error". Macro expansion and trigraph conversion don't happen. The -dD option also gets turned on automatically ๐ŸŽ€
    • With -fpreprocessed, predefinition of command line and most builtin macros is disabled. Contextual macros like "__LINE__" are handled normally. This lets you compile files that were previously preprocessed with "-E -fdirectives-only" ๐Ÿซถ
    • With both -E and -fpreprocessed, the -fpreprocessed rules win ๐Ÿ‘‘ This gives you full preprocessing of files that were earlier preprocessed with "-E -fdirectives-only" ๐Ÿ˜ญ
  • -fdollars-in-identifiers โ€” Lets $ show up inside identifiers ๐Ÿ’œ
  • -fextended-identifiers โ€” Lets identifiers use universal character names and extended characters ๐ŸŒˆ This one is on by default for C99 (and later C standards) and C++ โœจ
  • -fno-canonical-system-headers โ€” When preprocessing, your system header paths won't get shortened through canonicalization ๐Ÿ™ˆ
  • -fmax-include-depth=depth โ€” Sets how deep nested #includes can go ๐Ÿงš The default is 200.
  • -fsearch-include-path[=kind] โ€” Looks for input files on the #include path, not just in the current directory ๐Ÿ”ฅ This is super handy with C++20 modules, where header units and module interface units both need to be compiled directly:
g++ -c -std=c++20 -fmodules -fsearch-include-path bits/stdc++.h bits/std.cc
  • kind defaults to user, which searches the #include "..." path ๐Ÿ’– You can also explicitly ask for system to search the #include <...> path โœจ
  • -ftabstop=width โ€” Sets the distance between tab stops ๐Ÿ“ This helps the preprocessor report correct column numbers in warnings or errors, even when there are tabs on the line ๐Ÿ“ If the value is less than 1 or greater than 100, the option gets ignored. The default is 8.
  • -ftrack-macro-expansion[=level] โ€” Tracks where tokens are located across macro expansions ๐Ÿ” This lets the compiler show the current macro expansion stack when an error pops up inside a macro ๐Ÿ˜ญ Heads up though: using it makes the preprocessor and the compiler eat more memory ๐Ÿ’€ The level parameter lets you pick how precisely token locations get tracked, so you can dial down the memory use if you need to:
    • 0 turns this option off ๐Ÿ™…
    • 1 tracks token locations in a degraded mode to keep memory overhead minimal. In this mode, every token coming from expanding a function-like macro's argument shares the same location ๐Ÿซ 
    • 2 tracks token locations completely. This is the most memory hungry setting ๐Ÿท
    • If you give the option with no argument, the level defaults to 2 ๐ŸŒŸ
Also, -ftrack-macro-expansion=2 is turned on by default, so it's already working for you ๐Ÿ’…
  • -fmacro-prefix-map=old=new โ€” When you preprocess files living in the directory old, the "__FILE__" and "__BASE_FILE__" macros expand as if those files lived in directory new instead ๐Ÿฆ‹ You can use this to turn an absolute path into a relative one by using . for new, which can lead to more reproducible, location-independent builds ๐ŸŒˆ It also affects "__builtin_FILE()" during compilation. See also -ffile-prefix-map and -fcanon-prefix-map ๐Ÿ’œ
  • -fexec-charset=charset โ€” Sets the execution character set, which is used for string and character constants โœจ The default is UTF-8. The charset can be any encoding your system's "iconv" library routine supports ๐ŸŽ€
  • -fwide-exec-charset=charset โ€” Sets the wide execution character set, used for wide string and character constants ๐ŸŒธ The default is one of UTF-32BE, UTF-32LE, UTF-16BE, or UTF-16LE, whichever matches the width of "wchar_t" and the big-endian or little-endian byte order being used for code generation ๐Ÿงš Just like -fexec-charset, the charset can be any encoding your system's "iconv" routine supports. Fair warning though: you'll run into problems with encodings that don't fit exactly into "wchar_t" โš ๏ธ
  • -finput-charset=charset โ€” Sets the input character set, which gets translated from your input file's character set into the source character set GCC uses ๐Ÿซถ If the locale doesn't say what to use, or GCC can't get that info from the locale, the default is UTF-8. The locale or this command-line option can override it, but if they conflict, the command-line option wins ๐Ÿ‘‘ The charset can be any encoding your system's "iconv" library routine supports ๐ŸŒˆ
  • -fworking-directory โ€” Turns on linemarkers in the preprocessor output so the compiler knows the working directory at the time of preprocessing ๐Ÿ“ When it's enabled, the preprocessor emits a second linemarker right after the first one. That one has the current working directory followed by two slashes ๐Ÿ“ GCC uses this directory, when it shows up in the preprocessed input, as the directory listed as the current working directory in some debugging info formats ๐Ÿ” This option is switched on automatically if debugging info is enabled, but you can block it with the negated form -fno-working-directory ๐Ÿ™… Also, if -P is in your command line, this option does nothing, since no "#line" directives get emitted whatsoever ๐Ÿ’€
  • -A predicate=answer โ€” Makes an assertion with the predicate predicate and the answer answer ๐Ÿ’– This form is preferred over the older -A predicate(answer) form. That one still works, but this version doesn't use shell special characters, so it's way less messy ๐Ÿ’…
  • -A -predicate=answer โ€” Cancels an assertion with the predicate predicate and the answer answer ๐Ÿ™ˆ
  • -C โ€” Don't throw away comments ๐Ÿ’ฌ All comments get passed through to the output file, except comments inside processed directives, which get deleted along with the directive ๐Ÿ—‘๏ธ
Be ready for side effects with -C! It makes the preprocessor treat comments as tokens in their own right. For example, a comment at the start of what would be a directive line turns that line into an ordinary source line, since the first token on the line is no longer a # ๐Ÿ˜ญ
  • -CC โ€” Don't throw away comments, even during macro expansion ๐Ÿซถ This is like -C, except comments inside macros also get passed through to the output file wherever the macro gets expanded โœจ
    • On top of the -C side effects, -CC converts every C++-style comment inside a macro into a C-style comment. This stops a later use of that macro from accidentally commenting out the rest of the source line ๐Ÿ›ก๏ธ
    • -CC is generally used to support lint comments ๐Ÿงน
  • -P โ€” Stops linemarkers from showing up in the preprocessor output ๐Ÿšซ This might come in handy when you're running the preprocessor on something that isn't C code and will get sent to a program that could get confused by the linemarkers ๐ŸŒธ
  • -traditional, -traditional-cpp โ€” Tries to imitate the behavior of pre-standard C preprocessors instead of ISO C preprocessors ๐Ÿฆ•
    • GCC doesn't otherwise try to pretend to be a pre-standard C compiler, and these options are only supported with the -E switch or when you invoke CPP explicitly ๐Ÿ’…
  • -trigraphs โ€” Supports ISO C trigraphs ๐Ÿ”บ These are three-character sequences that all start with ??, and ISO C defines them to stand for single characters. For example, ??/ stands for \, so '??/n' is a character constant for a newline ๐Ÿ“
    • By default GCC ignores trigraphs, but in standard-conforming modes it converts them. Check out the -std and -ansi options ๐ŸŽ€
  • -remap โ€” Turns on special code to work around file systems that only allow super short file names, like MS-DOS ๐Ÿ“‚
  • -H โ€” Prints the name of each header file used, on top of all the other normal stuff ๐Ÿงš Each name is indented to show how deep it sits in the #include stack ๐Ÿชœ Precompiled header files get printed too, even if they turn out to be invalid. An invalid one shows up with ...x, and a valid one shows up with ...! โœ…
  • -dletters โ€” Makes debugging dumps during compilation, as specified by letters ๐Ÿ” The flags documented here are the ones relevant to the preprocessor. Other letters are either interpreted by the compiler proper, or reserved for future GCC versions, so they get silently ignored ๐Ÿคซ If you specify letters whose behavior conflicts, the result is undefined โš ๏ธ
    • -dM โ€” Instead of the normal output, this generates a list of #define directives for all the macros defined while the preprocessor runs, including predefined macros ๐Ÿ“œ It's a great way to see what's predefined in your version of the preprocessor. Assuming you have no file foo.h, this command shows all the predefined macros:
touch foo.h; cpp -dM foo.h
  • -dD โ€” Like -dM, except it outputs both the #define directives and the result of preprocessing ๐ŸŽ€ Both kinds of output go to the standard output file ๐Ÿซถ
  • -dN โ€” Like -dD, but only emits the macro names, not their expansions ๐Ÿ™ˆ
  • -dI โ€” Outputs #include directives in addition to the result of preprocessing ๐Ÿ“ฅ
  • -dU โ€” Like -dD, except only macros that get expanded, or whose definedness gets tested in preprocessor directives, are output ๐Ÿฆ‹ The output is delayed until the macro is used or tested. #undef directives are also output for macros that were tested but were undefined at that time ๐Ÿ’œ

-fdebug-cpp ๐Ÿ” Okay so this one is strictly for debugging GCC itself, bestie ๐Ÿ™ˆ When you use it from CPP or alongside -E, it dumps debugging info about location maps. Every token in the output gets the dump of whatever map its location belongs to. โœจ

When you use it from GCC without -E, it does absolutely nothing. Zero effect. ๐Ÿ’€

  • -I dir, -iquote dir, -isystem dir, -idirafter dir โ€” okay this is the big header-hunting crew ๐Ÿฆ‹ Each one adds dir to the list of places CPP searches for header files during preprocessing.

If dir starts with = or $SYSROOT, that bit gets swapped out for the sysroot prefix. See --sysroot and -isysroot for the tea on that. โ˜•

-iquote dirs only apply to the quote form, #include "file". Meanwhile -I, -isystem, and -idirafter dirs apply to both #include "file" and #include <file>. ๐Ÿ’…

You can stack as many of these as you want to search a bunch of folders. The lookup order goes like this:

  1. For the quote form, the directory of the current file gets checked first. ๐Ÿ“‚
  2. For the quote form, the -iquote dirs get searched left-to-right, in the order they show up on the command line. ๐ŸŽ€
  3. -I dirs get scanned left-to-right. ๐ŸŒธ
  4. -isystem dirs get scanned left-to-right. ๐Ÿงš
  5. The standard system dirs get scanned. ๐Ÿ›๏ธ
  6. -idirafter dirs get scanned left-to-right. ๐ŸŒ™

You can use -I to override a system header and swap in your own version, since those dirs get searched before the standard system ones. BUT, and this is important, do NOT use -I to add dirs full of vendor-supplied system headers. Use -isystem for that. ๐Ÿ™…โ€โ™€๏ธ

-isystem and -idirafter also mark the dir as a system directory, so it gets the same special treatment the standard system dirs get. ๐Ÿ‘‘

If a standard system include dir, or a dir you gave to -isystem, is also given with -I, then the -I gets ignored. The dir still gets searched, just as a system dir in its normal spot in the system include chain. This keeps GCC's procedure for fixing buggy system headers and the ordering for #include_next from getting messed up by accident. If you truly need to change the search order for system dirs, use -nostdinc and/or -isystem instead. ๐Ÿซถ

  • -I- โ€” ugh, this one's a little drama ๐Ÿ˜ญ It splits the include path, and it's deprecated. Please use -iquote instead for the -I dirs that come before the -I-, then delete the -I- entirely. ๐Ÿ—‘๏ธ

Any dirs given with -I before -I- only get searched for headers requested with #include "file". They are NOT searched for #include <file>. If you add more -I dirs after the -I-, those get searched for every #include directive.

On top of that, -I- stops the directory of the current file from being the first place searched for #include "file". There's no way to undo that effect, so choose wisely. ๐Ÿ™ƒ

  • -iprefix prefix โ€” sets prefix as the prefix for any -iwithprefix options that come after it. If the prefix is a directory, make sure you include the final /. ๐Ÿ“
  • -iwithprefix dir, -iwithprefixbefore dir โ€” tacks dir onto the prefix you set earlier with -iprefix, then adds the result to the include search path. โœจ -iwithprefixbefore puts it in the same spot -I would, while -iwithprefix puts it where -idirafter would. ๐Ÿง
  • -isysroot dir โ€” basically the same vibe as --sysroot, but it only applies to header files. The exception is Darwin targets, where it applies to both headers and libraries. Check out --sysroot for more info. ๐Ÿ“
  • -imultilib dir โ€” uses dir as a subdirectory of the directory that holds the target-specific C++ headers. ๐ŸŒˆ
  • -nostdinc โ€” no standard system dirs for header hunting, bestie ๐Ÿ™…โ€โ™€๏ธ Only the dirs you explicitly pass with -I, -iquote, -isystem, and/or -idirafter get searched, plus the directory of the current file if it applies. ๐Ÿ“‚
  • -nostdinc++ โ€” skips the C++-specific standard dirs, but still searches the other standard ones. (This one's used when building the C++ library, so it's very behind-the-scenes energy ๐Ÿ”ง)
  • --embed-dir=dir โ€” appends dir to the list of searched directories for the #embed preprocessing directive or the __has_embed macro. There are no default directories for #embed, so you have to bring your own. ๐Ÿฆ‹

If dir starts with = or $SYSROOT, that gets replaced with the sysroot prefix, same as before. See --sysroot and -isysroot. โœจ

  • -Wcomment, -Wcomments โ€” warns whenever a /* shows up inside a /* comment, or whenever a backslash-newline shows up in a // comment. This one's turned on by -Wall. ๐Ÿ”ฅ
  • -Wtrigraphs โ€” warns if any trigraphs get encountered that might change what the program means. Trigraphs inside comments don't get warned about, EXCEPT the ones that would form escaped newlines. ๐Ÿ™ˆ

This is implied by -Wall. If -Wall isn't given, it's still enabled unless trigraphs are enabled. Want trigraph conversion without the warnings but still want the other -Wall warnings? Use -trigraphs -Wall -Wno-trigraphs. ๐Ÿ’œ

  • -Wundef โ€” warns if an undefined identifier gets evaluated in an #if directive. Those identifiers get replaced with zero. ๐Ÿงฎ
  • -Wexpansion-to-defined โ€” warns whenever defined shows up in the expansion of a macro, including when the macro gets expanded by an #if directive. This usage isn't portable, so it's a red flag, babe ๐Ÿšฉ This warning is also enabled by -Wpedantic and -Wextra.
  • -Wunused-macros โ€” warns about macros defined in the main file that never get used. A macro counts as used if it's expanded or tested for existence at least once. The preprocessor also warns if a macro hasn't been used by the time it gets redefined or undefined. ๐Ÿ•ต๏ธโ€โ™€๏ธ

Built-in macros, macros defined on the command line, and macros defined in include files are NOT warned about. ๐Ÿ™…โ€โ™€๏ธ

Heads up: if a macro is actually used, but ONLY in skipped conditional blocks, the preprocessor still reports it as unused. To dodge the warning in that case, you might improve the scope of the macro's definition, like moving it into the first skipped block. Or you could give it a dummy use with something like this:
#if defined the_macro_causing_the_warning
#endif
  • -Wno-endif-labels โ€” stops the warning for when an #else or an #endif is followed by text. This happens sometimes in older programs with code like this:
#if FOO
...
#else FOO
...
#endif FOO

The second and third FOO should be in comments. ๐Ÿซ  This warning is on by default.

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

Okay this section is all about the environment variables that change how CPP operates โœจ You can use them to specify directories or prefixes for searching include files, or to control dependency output. ๐Ÿ’–

Also, you can specify places to search with options like -I, and control dependency output with options like -M. Those take precedence over environment variables, and environment variables take precedence over the configuration of GCC. Pecking order, babe ๐Ÿ‘‘

๐Ÿ—‚๏ธ CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH

Each one of these has a value that's a list of directories, separated by a special character, kind of like PATH. Those directories are where it looks for header files. The special character, PATH_SEPARATOR, depends on the target and gets decided when GCC is built. For Microsoft Windows-based targets it's a semicolon, and for pretty much everything else it's a colon. ๐ŸŒˆ

CPATH specifies a list of directories to be searched as if you'd given them with -I, but after any paths you gave with -I options on the command line. This variable gets used no matter which language is being preprocessed. ๐Ÿฆ‹

The remaining variables only apply when preprocessing the particular language they're named after. Each one specifies a list of directories to be searched as if you'd given them with -isystem, but after any paths you gave with -isystem options on the command line. ๐Ÿงš

In all of these variables, an empty element tells the compiler to search its current working directory. Empty elements can show up at the beginning or end of a path. For example, if the value of CPATH is ":/special/include", that has the same effect as -I. -I/special/include. ๐Ÿ“

๐Ÿ“ฌ DEPENDENCIES_OUTPUT

If this variable is set, its value says how to output dependencies for Make, based on the non-system header files the compiler processes. System header files get ignored in the dependency output. ๐Ÿ™ˆ

The value can be just a file name, in which case the Make rules get written to that file, and the target name gets guessed from the source file name. Or the value can take the form file target, in which case the rules get written to file using target as the target name. โœจ

In other words, this variable is equivalent to combining the options -MM and -MF, with an optional -MT switch too. ๐Ÿ’…

๐ŸŒท SUNPRO_DEPENDENCIES

This one is the same as DEPENDENCIES_OUTPUT, except system header files are NOT ignored. So it implies -M rather than -MM. However, the dependence on the main input file is omitted. ๐ŸŽ€

โฐ SOURCE_DATE_EPOCH

If this variable is set, its value specifies a UNIX timestamp to be used instead of the current date and time in the __DATE__ and __TIME__ macros. That way the embedded timestamps stay reproducible. ๐Ÿ”๐Ÿ’–

The value of SOURCE_DATE_EPOCH must be a UNIX timestamp, which is defined as the number of seconds (excluding leap seconds) since 01 Jan 1970 00:00:00, represented in ASCII. It's identical to the output of date +%s on GNU/Linux and other systems that support the %s extension in the date command. ๐Ÿ•ฐ๏ธ

The value should be a known timestamp, like the last modification time of the source or package, and it should be set by the build process. ๐Ÿซถ

โœจ SEE ALSO โœจ

okay bestie, this is your reading list ๐Ÿ“š๐Ÿซถ go check out gpl(7), gfdl(7), and fsf-funding(7), then gcc(1). And don't forget the Info entries for cpp AND gcc, they're lowkey the best-written docs out there ๐Ÿค“โœจ


Copyright (c) 1987-2025 Free Software Foundation, Inc. ๐Ÿ’œ

okay so the whole document is free to copy, distribute, and/or modify under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation ๐Ÿฆ‹ the full license is included in gfdl(7), so go read that if you wanna know the fine print ๐Ÿ“œ. This manual has no Invariant Sections (no cap, nothing is locked down ๐Ÿ™…โ€โ™€๏ธ).

The Front-Cover Text is:

A GNU Manual

The Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.

It's literally giving freedom ๐ŸŒˆ๐Ÿ’– and the copies people buy help fund GNU development, so you're basically supporting the squad every time you grab one ๐Ÿซถโœจ


Okay bestie, that's the whole page, you made it to the end ๐Ÿฅน๐Ÿ’… this was a gcc-15 page, dated 2025-09-17, and it's the CPP(1) manual. Slay the preprocessor and go do something iconic ๐Ÿ‘‘๐ŸŽ€

๐Ÿ“ฆ where this page comes from