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
libobjc
library to make an Objective-C program work. .mi
.mm
.M
libobjc
library to make an Objective-C++ program work. Note that ‘.M
’ refers to a literal capital M. .mii
.h
-fdump-ada-spec
switch). .cc
.cp
.cxx
.cpp
.CPP
.c++
.C
.cxx
’, the last two letters must both be literally ‘x
’. Likewise, ‘.C
’ refers to a literal capital C. .mm
.M
.mii
.hh
.H
.hp
.hxx
.hpp
.HPP
.h++
.tcc
.f
.for
.ftn
.F
.FOR
.fpp
.FPP
.FTN
.f90
.f95
.f03
.f08
.F90
.F95
.F03
.F08
.go
.ads
.adb
.s
.S
.sx
You can specify the input language explicitly with the -x
option:
-x
language
-x
option. Possible values for language are: c c-header 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 f77 f77-cpp-input f95 f95-cpp-input go java
-x none
-x
has not been used at all). -pass-exit-codes
gcc
program exits 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 instead returns with the numerically highest error produced by any phase returning an error indication. The C, C++, and Fortran front ends 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
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
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
Input files that don't require preprocessing are ignored.
-o
file
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
-###
-v
except the commands are not executed and arguments are quoted unless they contain only alphanumeric characters or ./-_
. This is useful for shell scripts to capture the driver-generated command lines. -pipe
--help
gcc
. If the -v
option is also specified then --help
is also 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 that have no documentation associated with them are also displayed. --target-help
--help={
class|[^
]qualifier}
[,...
]
optimizers
’warnings
’target
’--target-help
option however, target-specific options of the linker and assembler are not displayed. This is because those tools do not currently support the extended --help=
syntax. params
’--param
option. common
’These are the supported qualifiers:
undocumented
’joined
’--help=target
’. separate
’-o output-file
’. Thus for example to display all the undocumented target-specific switches supported by the compiler, use:
--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) that have a description, use:
--help=warnings,^joined,^undocumented
The argument to --help=
should not consist solely of inverted qualifiers.
Combining several classes is possible, although this usually restricts the output so much that there is nothing to display. One case where it does work, however, is when one of the classes is target. For example, to display all the target-specific optimization options, use:
--help=target,optimizers
The --help=
option can be repeated on the command line. Each successive use displays 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:
-Q -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
-no-canonical-prefixes
/../
’ or ‘/./
’, or make the path absolute when generating a relative prefix. --version
-wrapper
gcc -c t.c -wrapper gdb,--args
This invokes all subprograms of gcc
under ‘gdb --args
’, thus the invocation of cc1
is ‘gdb --args cc1 ...
’.
-fplugin=
name.so
-fplugin-arg-
name-
key=
value
-fdump-ada-spec
[-slim
]
-fada-spec-parent=
unit
-fdump-ada-spec[-slim]
above, generate Ada specs as child units of parent unit. -fdump-go-spec=
file
const
, type
, var
, and func
declarations which may be a useful way to start writing a Go interface to code written in some other language. @
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.
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/Overall-Options.html