Search notes:

Some interesting GCC command line options

The following is a list of some options gcc command line options that I came across and that I found noteworthy.
-ansi Equivalent to -std=c89.
-c
-C and -CC instructs the preprocessor to keep comments.
-d
-dM generates a list of #define directives, including predefined macros.
-D defines the value of a macro.
-dumpmachine prints the target triplet.
-dumpspec
-E Only preprocess file.
-f to set many boolean like options.
-g Include debugging information.
-H Print the names of each header file that is processed. Each #include indents one level, finishing a file dedents one level.
-include file Pretend the source file started with #include "file"
-m
-M show dependencies of a compilation unit (including system header files).
-MM show dependencies of a compilation unit (without system header files).
-masm Select the (dis-)assembly dialect.
-nodefaultlibs
-nostartfiles
-nostdlib Pass only files to the linker that are explicitly specified.
-O Specify optimization.
-P Prevent the preprocessor from including line markers in its output.
-pedantic and -pedantic-errors Compare with -Werror=pedantic
-pipe Output of one stage is passed to the next stage via pipe rather than temporary file. Can improve performance but uses more memory.
--print-libgcc-file-name
-print-prog-name
-print-search-dirs reveal the directories that gcc searches for programs and libraries.
-Q
-s remove all symbol table and relocation information from the executable.
-save-temps Don't delete intermediate outputs (*.s, *.i, *.o).
-S create assembler code (*.s)
-shared Instruct the linker to create a shared object.
-std Choose the standard, for example -std=c99 or -std=gnu89.
-v
--version Prints the version of the compiler
-W Enable warning messages
-Wa,option-1[,option-2…] Pass options to the assembler.
-Wl,linker-option Pass options to the linker.
-Wp,preprocessor-option Pass options to the preprocessor.
-x Specify language of input file
@option-file

TODO

Target specific options can be queried with gcc --target-help.

See also

Options specifically for Cygwin and MinGW.

Links

GCC manual: option summary, Option index

Index