Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file.
For any given input file, the file name suffix determines what kind of compilation is done:
.c
.i
.ii
.m
.mi
.mm
.M
.mii
.h
.cc
.cp
.cxx
.cpp
.CPP
.c++
.C
.mm
.M
.mii
.hh
.H
.hp
.hxx
.hpp
.HPP
.h++
.tcc
.f
.for
.FOR
.F
.fpp
.FPP
.f90
.f95
.F90
.F95
.ads
.adb
.s
.S
.sx
You can specify the input language explicitly with the -x option:
-x
language
c c-header c-cpp-output c++ c++-header c++-cpp-output objective-c objective-c-header objective-c-cpp-output objective-c++ objective-c++-header objective-c++-cpp-output assembler assembler-with-cpp ada f95 f95-cpp-input java treelang
-x none
-pass-exit-codes
Normally the gcc program will exit with the code of 1 if any phase of the compiler returns a non-success return code. If you specify -pass-exit-codes, the gcc program will instead return with numerically highest error produced by any phase that returned an error indication. The C, C++, and Fortran frontends return 4, if an internal compiler error is encountered.
If you only want some of the stages of compilation, you can use -x (or filename suffixes) to tell gcc where to start, and one of the options -c, -S, or -E to say where gcc is to stop. Note that some combinations (for example, -x cpp-output -E) instruct gcc to do nothing at all.
-c
Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file.
By default, the object file name for a source file is made by replacing the suffix .c, .i, .s, etc., with .o.
Unrecognized input files, not requiring compilation or assembly, are
ignored.
-S
Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified.
By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.
Input files that don't require compilation are ignored.
-E
Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.
Input files which don't require preprocessing are ignored.
-o
file
Place output in file file. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
If -o is not specified, the default is to put an executable
file in a.out, the object file for
source
.
suffix in source
.o, its
assembler file in source
.s, a precompiled header file in
source
.
suffix
.gch, and all preprocessed C source on
standard output.
-v
Print (on standard error output) the commands executed to run the stages
of compilation. Also print the version number of the compiler driver
program and of the preprocessor and the compiler proper.
-###
Like -v except the commands are not executed and all command
arguments are quoted. This is useful for shell scripts to capture the
driver-generated command lines.
-pipe
Use pipes rather than temporary files for communication between the
various stages of compilation. This fails to work on some systems where
the assembler is unable to read from a pipe; but the GNU assembler has
no trouble.
-combine
If you are compiling multiple source files, this option tells the driver
to pass all the source files to the compiler at once (for those
languages for which the compiler can handle this). This will allow
intermodule analysis (IMA) to be performed by the compiler. Currently the only
language for which this is supported is C. If you pass source files for
multiple languages to the driver, using this option, the driver will invoke
the compiler(s) that support IMA once each, passing each compiler all the
source files appropriate for it. For those languages that do not support
IMA this option will be ignored, and the compiler will be invoked once for
each source file in that language. If you use this option in conjunction
with -save-temps, the compiler will generate multiple
pre-processed files
(one for each source file), but only one (combined) .o or
.s file.
--help
Print (on the standard output) a description of the command line options
understood by gcc. If the -v option is also specified
then --help will also be passed on to the various processes
invoked by gcc, so that they can display the command line options
they accept. If the -Wextra option has also been specified
(prior to the --help option), then command line options which
have no documentation associated with them will also be displayed.
--target-help
Print (on the standard output) a description of target-specific command
line options for each tool. For some targets extra target-specific
information may also be printed.
--help=
class
[
,
qualifier
]
It is possible to further refine the output of the --help= option by adding a comma separated list of qualifiers after the class. These can be any from the following list:
Thus for example to display all the undocumented target-specific switches supported by the compiler the following can be used:
--help=target,undocumented
The sense of a qualifier can be inverted by prefixing it with the ^ character, so for example to display all binary warning options (i.e., ones that are either on or off and that do not take an argument), which have a description the following can be used:
--help=warnings,^joined,^undocumented
A class can also be used as a qualifier, although this usually restricts the output by so much that there is nothing to display. One case where it does work however is when one of the subjects is target. So for example to display all the target-specific optimization options the following can be used:
--help=target,optimizers
The --help= option can be repeated on the command line. Each successive use will display its requested class of options, skipping those that have already been displayed.
If the -Q option appears on the command line before the --help= option, then the descriptive text displayed by --help= is changed. Instead of describing the displayed options, an indication is given as to whether the option is enabled, disabled or set to a specific value (assuming that the compiler knows this at the point where the --help= option is used).
Here is a truncated example from the ARM port of gcc:
% gcc -Q -mabi=2 --help=target -c The following options are target specific: -mabi= 2 -mabort-on-noreturn [disabled] -mapcs [disabled]
The output is sensitive to the effects of previous command line options, so for example it is possible to find out which optimizations are enabled at -O2 by using:
-O2 --help=optimizers
Alternatively you can discover which binary optimizations are enabled by -O3 by using:
gcc -c -Q -O3 --help=optimizers > /tmp/O3-opts gcc -c -Q -O2 --help=optimizers > /tmp/O2-opts diff /tmp/O2-opts /tmp/O3-opts | grep enabled
--version
Display the version number and copyrights of the invoked GCC.
@
file
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively.