| [Top] | [Contents] | [Index] | [ ? ] |
This manual documents how to run and install the GNU compiler, as well as its new features and incompatibilities, and how to report bugs. It corresponds to GCC version 2.96.
1. Compile C, C++, or Objective C You can compile C or C++ programs. 2. GNU CC Command Options Command options supported by `gcc'. 3. Extensions to the C Language Family GNU extensions to the C language family. 4. Extensions to the C++ Language GNU extensions to the C++ language. 5. Known Causes of Trouble with GNU CC If you have trouble installing GNU CC. 6. Reporting Bugs How, why and where to report bugs. 7. How To Get Help with GNU CC How to find suppliers of support for GNU CC. 8. Contributing to GNU CC Development How to contribute to testing and developing GNU CC.
Index Index of concepts and symbol names.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The C, C++, and Objective C versions of the compiler are integrated; the GNU C compiler can compile programs written in C, C++, or Objective C.
"GCC" is a common shorthand term for the GNU C compiler. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs.
When referring to C++ compilation, it is usual to call the compiler "G++". Since there is only one compiler, it is also accurate to call it "GCC" no matter what the language context; however, the term "G++" is more useful when the emphasis is on compiling C++ programs.
We use the name "GNU CC" to refer to the compilation system as a whole, and more specifically to the language-independent part of the compiler. For example, we refer to the optimization options as affecting the behavior of "GNU CC" or sometimes just "the compiler".
Front ends for other languages, such as Ada 9X, Fortran, Modula-3, and Pascal, are under development. These front-ends, like that for C++, are built in subdirectories of GNU CC and link to it. The result is an integrated compiler that can compile programs written in C, C++, Objective C, or any of the languages for which you have installed front ends.
In this manual, we only discuss the options for the C, Objective-C, and C++ compilers and those of the GNU CC core. Consult the documentation of the other front ends for the options to use when compiling programs written in other languages.
G++ is a compiler, not merely a preprocessor. G++ builds object code directly from your C++ program source. There is no intermediate C version of the program. (By contrast, for example, some other implementations use a program that generates a C program from your C++ source.) Avoiding an intermediate C representation of the program means that you get better object code, and better debugging information. The GNU debugger, GDB, works with this information in the object code to give you comprehensive C++ source-level editing capabilities (see section `C and C++' in Debugging with GDB).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When you invoke GNU CC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the `-c' option says not to run the linker. Then the output consists of object files output by the assembler.
Other options are passed on to one stage of processing. Some options control the preprocessor and others the compiler itself. Yet other options control the assembler and linker; most of these are not documented here, since you rarely need to use any of them.
Most of the command line options that you can use with GNU CC are useful for C programs; when an option is only useful with another language (usually C++), the explanation says so explicitly. If the description for a particular option does not mention a source language, you can use that option with all supported languages.
See section Compiling C++ Programs, for a summary of special options for compiling C++ programs.
The gcc program accepts options and file names as operands. Many
options have multiletter names; therefore multiple single-letter options
may not be grouped: `-dr' is very different from `-d
-r'.
You can mix options and other arguments. For the most part, the order you use doesn't matter. Order does matter when you use several options of the same kind; for example, if you specify `-L' more than once, the directories are searched in the order specified.
Many options have long names starting with `-f' or with `-W'---for example, `-fforce-mem', `-fstrength-reduce', `-Wformat' and so on. Most of these have both positive and negative forms; the negative form of `-ffoo' would be `-fno-foo'. This manual documents only one of these two forms, whichever one is not the default.
2.1 Option Summary Brief list of all options, without explanations. 2.2 Options Controlling the Kind of Output Controlling the kind of output: an executable, object files, assembler files, or preprocessed source. 2.3 Compiling C++ Programs Compiling C++ programs. 2.4 Options Controlling C Dialect Controlling the variant of C language compiled. 2.5 Options Controlling C++ Dialect Variations on C++. 2.6 Options to Request or Suppress Warnings How picky should the compiler be? 2.7 Options for Debugging Your Program or GNU CC Symbol tables, measurements, and debugging dumps. 2.8 Options That Control Optimization How much optimization? 2.9 Options Controlling the Preprocessor Controlling header files and macro definitions. Also, getting dependency information for Make. 2.10 Passing Options to the Assembler Passing options to the assembler. 2.11 Options for Linking Specifying libraries and so on. 2.12 Options for Directory Search Where to find header files and libraries. Where to find the compiler executable files. 2.13 Specifying Target Machine and Compiler Version Running a cross-compiler, or an old version of GNU CC. 2.14 Hardware Models and Configurations Specifying minor hardware or convention variations, such as 68010 vs 68020. 2.15 Options for Code Generation Conventions Specifying conventions for function calls, data layout and register usage. 2.16 Environment Variables Affecting GNU CC Env vars that affect GNU CC.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is a summary of all the options, grouped by type. Explanations are in the following sections.
-c -S -E -o file -pipe -v --help -x language |
-ansi -flang-isoc9x -fallow-single-precision -fcond-mismatch -fno-asm -fno-builtin -ffreestanding -fhosted -fsigned-bitfields -fsigned-char -funsigned-bitfields -funsigned-char -fwritable-strings -traditional -traditional-cpp -trigraphs |
-fno-access-control -fcheck-new -fconserve-space -fdollars-in-identifiers -fno-elide-constructors -fexternal-templates -ffor-scope -fno-for-scope -fno-gnu-keywords -fguiding-decls -fhandle-signatures -fhonor-std -fhuge-objects -fno-implicit-templates -finit-priority -fno-implement-inlines -fname-mangling-version-n -fno-default-inline -foperator-names -fno-optional-diags -fpermissive -frepo -fstrict-prototype -fsquangle -ftemplate-depth-n -fthis-is-variable -fvtable-thunks -nostdinc++ -Wctor-dtor-privacy -Wno-deprecated -Weffc++ -Wno-non-template-friend -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wno-pmf-conversions -Wreorder -Wsign-promo -Wsynth |
-fsyntax-only -pedantic -pedantic-errors -w -W -Wall -Waggregate-return -Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Werror -Wformat -Wid-clash-len -Wimplicit -Wimplicit-int -Wimplicit-function-declaration -Wimport -Werror-implicit-function-declaration -Winline -Wlarger-than-len -Wlong-long -Wmain -Wmissing-declarations -Wmissing-noreturn -Wmissing-prototypes -Wmultichar -Wnested-externs -Wno-import -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare -Wstrict-prototypes -Wswitch -Wtraditional -Wtrigraphs -Wundef -Wuninitialized -Wunused -Wwrite-strings -Wunknown-pragmas |
-a -ax -dletters -fdump-unnumbered -fpretend-float -fprofile-arcs -ftest-coverage -g -glevel -gcoff -gdwarf -gdwarf-1 -gdwarf-1+ -gdwarf-2 -ggdb -gstabs -gstabs+ -gxcoff -gxcoff+ -p -pg -print-file-name=library -print-libgcc-file-name -print-prog-name=program -print-search-dirs -save-temps |
-fbranch-probabilities -foptimize-register-moves -fcaller-saves -fcse-follow-jumps -fcse-skip-blocks -fdelayed-branch -fexpensive-optimizations -ffast-math -ffloat-store -fforce-addr -fforce-mem -fdata-sections -ffunction-sections -fgcse -finline-functions -finline-limit-n -fkeep-inline-functions -fno-default-inline -fno-defer-pop -fno-function-cse -fno-inline -fno-peephole -fomit-frame-pointer -fregmove -frerun-cse-after-loop -frerun-loop-opt -fschedule-insns -fschedule-insns2 -fstrength-reduce -fthread-jumps -funroll-all-loops -funroll-loops -fmove-all-movables -freduce-all-givs -fstrict-aliasing -O -O0 -O1 -O2 -O3 -Os |
-Aquestion(answer) -C -dD -dM -dN -Dmacro[=defn] -E -H -idirafter dir -include file -imacros file -iprefix file -iwithprefix dir -iwithprefixbefore dir -isystem dir -isystem-c++ dir -M -MD -MM -MMD -MG -nostdinc -P -trigraphs -undef -Umacro -Wp,option |
-Wa,option |
object-file-name -llibrary -nostartfiles -nodefaultlibs -nostdlib -s -static -shared -symbolic -Wl,option -Xlinker option -u symbol |
-Bprefix -Idir -I- -Ldir -specs=file |
-b machine -V version |
M680x0 Options -m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 -m68060 -mcpu32 -m5200 -m68881 -mbitfield -mc68000 -mc68020 -mfpa -mnobitfield -mrtd -mshort -msoft-float -mpcrel -malign-int SPARC Options -mcpu=cpu type -mtune=cpu type -mcmodel=code model -malign-jumps=num -malign-loops=num -malign-functions=num -m32 -m64 -mapp-regs -mbroken-saverestore -mcypress -mepilogue -mflat -mfpu -mhard-float -mhard-quad-float -mimpure-text -mlive-g0 -mno-app-regs -mno-epilogue -mno-flat -mno-fpu -mno-impure-text -mno-stack-bias -mno-unaligned-doubles -msoft-float -msoft-quad-float -msparclite -mstack-bias -msupersparc -munaligned-doubles -mv8 ARM Options -mapcs-frame -mno-apcs-frame -mapcs-26 -mapcs-32 -mapcs-stack-check -mno-apcs-stack-check -mapcs-float -mno-apcs-float -mapcs-reentrant -mno-apcs-reentrant -msched-prolog -mno-sched-prolog -mlittle-endian -mbig-endian -mwords-little-endian -mshort-load-bytes -mno-short-load-bytes -mshort-load-words -mno-short-load-words -msoft-float -mhard-float -mfpe -mthumb-interwork -mno-thumb-interwork -mcpu= -march= -mfpe= -mstructure-size-boundary= -mbsd -mxopen -mno-symrename -mabort-on-noreturn -mno-sched-prolog -mlongcall -fbitfield-access-32bit Thumb Options -mtpcs-frame -mno-tpcs-frame -mtpcs-leaf-frame -mno-tpcs-leaf-frame -mlittle-endian -mbig-endian -mthumb-interwork -mno-thumb-interwork -mstructure-size-boundary= RS/6000 and PowerPC Options -mcpu=cpu type -mtune=cpu type -mpower -mno-power -mpower2 -mno-power2 -mpowerpc -mno-powerpc -mpowerpc-gpopt -mno-powerpc-gpopt -mpowerpc-gfxopt -mno-powerpc-gfxopt -mnew-mnemonics -mno-new-mnemonics -mfull-toc -mminimal-toc -mno-fop-in-toc -mno-sum-in-toc -maix64 -maix32 -mxl-call -mno-xl-call -mthreads -mpe -msoft-float -mhard-float -mmultiple -mno-multiple -mstring -mno-string -mupdate -mno-update -mfused-madd -mno-fused-madd -mbit-align -mno-bit-align -mstrict-align -mno-strict-align -mrelocatable -mno-relocatable -mrelocatable-lib -mno-relocatable-lib -mtoc -mno-toc -mlittle -mlittle-endian -mbig -mbig-endian -mcall-aix -mcall-sysv -mprototype -mno-prototype -msim -mmvme -mads -myellowknife -memb -msdata -msdata=opt -G num -mlongcall -fvec -fvec-eabi MIPS Options -mabicalls -mcpu=cpu type -membedded-data -membedded-pic -mfp32 -mfp64 -mgas -mgp32 -mgp64 -mgpopt -mhalf-pic -mhard-float -mint64 -mips1 -mips2 -mips3 -mips4 -mips5 -mips32 -mips64 -mlong64 -mlong32 -mlong-calls -mmemcpy -mmips-as -mmips-tfile -mno-abicalls -mno-embedded-data -mno-embedded-pic -mno-gpopt -mno-long-calls -mno-memcpy -mno-mips-tfile -mno-rnames -mno-stats -mrnames -msoft-float -m4650 -msingle-float -mmad -mstats -EL -EB -G num -nocpp -mabi=32 -mabi=n32 -mabi=64 -mabi=eabi i386 Options -mcpu=cpu type -march=cpu type -mieee-fp -mno-fancy-math-387 -mno-fp-ret-in-387 -msoft-float -msvr3-shlib -mno-wide-multiply -mrtd -malign-double -mreg-alloc=list -mregparm=num -malign-jumps=num -malign-loops=num -malign-functions=num -mpreferred-stack-boundary=num SH Options -ml -mb -m1 -m2 -m3 -m3e -m4single-only -m4-single -m4 -mrelax -mbigtable -mdalign -mfmovd -mhitachi -mieee -mno-ieee -misize -mpadstruct -mspace |
-fcall-saved-reg -fcall-used-reg -fexceptions -ffixed-reg -finhibit-size-directive -fcheck-memory-usage -fprefix-function-name -fno-common -fno-ident -fno-gnu-linker -fpcc-struct-return -fpic -fPIC -freg-struct-return -fshared-data -fshort-enums -fshort-double -fvolatile -fvolatile-global -fvolatile-static -fverbose-asm -fpack-struct -fstack-check -fargument-alias -fargument-noalias -fargument-noalias-global -fleading-underscore |
2.2 Options Controlling the Kind of Output Controlling the kind of output: an executable, object files, assembler files, or preprocessed source. 2.4 Options Controlling C Dialect Controlling the variant of C language compiled. 2.5 Options Controlling C++ Dialect Variations on C++. 2.6 Options to Request or Suppress Warnings How picky should the compiler be? 2.7 Options for Debugging Your Program or GNU CC Symbol tables, measurements, and debugging dumps. 2.8 Options That Control Optimization How much optimization? 2.9 Options Controlling the Preprocessor Controlling header files and macro definitions. Also, getting dependency information for Make. 2.10 Passing Options to the Assembler Passing options to the assembler. 2.11 Options for Linking Specifying libraries and so on. 2.12 Options for Directory Search Where to find header files and libraries. Where to find the compiler executable files. 2.13 Specifying Target Machine and Compiler Version Running a cross-compiler, or an old version of GNU CC.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. The first three stages apply to an individual source file, and end by producing an object file; 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:
file.c
file.i
file.ii
file.m
file.h
file.cc
file.cxx
file.cpp
file.C
file.s
file.S
other
You can specify the input language explicitly with the `-x' option:
-x language
c objective-c c++ c-header cpp-output c++-cpp-output assembler assembler-with-cpp |
-x none
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 which don't require preprocessing are ignored.
-o file
Since only one output file can be specified, it does not make sense to use `-o' when compiling more than one input file, unless you are producing an executable file as output.
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', and all preprocessed C source on standard output.
-v
-pipe
--help
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 -W option is also specified then command
line options which have no documentation associated with them will also
be displayed.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
C++ source files conventionally use one of the suffixes `.C',
`.cc', `.cpp', `.c++', `.cp', or `.cxx';
preprocessed C++ files use the suffix `.ii'. GNU CC recognizes
files with these names and compiles them as C++ programs even if you
call the compiler the same way as for compiling C programs (usually with
the name gcc).
However, C++ programs often require class libraries as well as a
compiler that understands the C++ language--and under some
circumstances, you might want to compile programs from standard input,
or otherwise without a suffix that flags them as C++ programs.
g++ is a program that calls GNU CC with the default language
set to C++, and automatically specifies linking against the C++
library. On many systems, the script g++ is also
installed with the name c++.
When you compile C++ programs, you may specify many of the same command-line options that you use for compiling programs in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for C++ programs. See section Options Controlling C Dialect, for explanations of options for languages related to C. See section Options Controlling C++ Dialect, for explanations of options that are meaningful only for C++ programs.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following options control the dialect of C (or languages derived from C, such as C++ and Objective C) that the compiler accepts:
-ansi
This turns off certain features of GNU C that are incompatible with ANSI
C, such as the asm, inline and typeof keywords, and
predefined macros such as unix and vax that identify the
type of system you are using. It also enables the undesirable and
rarely used ANSI trigraph feature, and it disables recognition of C++
style `//' comments.
The alternate keywords __asm__, __extension__,
__inline__ and __typeof__ continue to work despite
`-ansi'. You would not want to use them in an ANSI C program, of
course, but it is useful to put them in header files that might be included
in compilations done with `-ansi'. Alternate predefined macros
such as __unix__ and __vax__ are also available, with or
without `-ansi'.
The `-ansi' option does not cause non-ANSI programs to be rejected gratuitously. For that, `-pedantic' is required in addition to `-ansi'. See section 2.6 Options to Request or Suppress Warnings.
The macro __STRICT_ANSI__ is predefined when the `-ansi'
option is used. Some header files may notice this macro and refrain
from declaring certain functions or defining certain macros that the
ANSI standard doesn't call for; this is to avoid interfering with any
programs that might use these names for other things.
The functions alloca, abort, exit, and
_exit are not builtin functions when `-ansi' is used.
-flang-isoc9x
restrict keyword.
Even when this option is not specified, you can still use some C9X
features in so far as they do not conflict with previous C standards.
For example, you may use __restrict__ even when -flang-isoc9x
is not specified.
-fno-asm
asm, inline or typeof as a
keyword, so that code can use these words as identifiers. You can use
the keywords __asm__, __inline__ and __typeof__
instead. `-ansi' implies `-fno-asm'.
In C++, this switch only affects the typeof keyword, since
asm and inline are standard keywords. You may want to
use the `-fno-gnu-keywords' flag instead, as it also disables the
other, C++-specific, extension keywords such as headof.
-fno-builtin
abort,
abs, alloca, cos, exit, fabs,
ffs, labs, memcmp, memcpy, sin,
sqrt, strcmp, strcpy, and strlen.
GCC normally generates special code to handle certain builtin functions
more efficiently; for instance, calls to alloca may become single
instructions that adjust the stack directly, and calls to memcpy
may become inline copy loops. The resulting code is often both smaller
and faster, but since the function calls no longer appear as such, you
cannot set a breakpoint on those calls, nor can you change the behavior
of the functions by linking with a different library.
The `-ansi' option prevents alloca and ffs from being
builtin functions, since these functions do not have an ANSI standard
meaning.
-fhosted
Assert that compilation takes place in a hosted environment. This implies
`-fbuiltin'. A hosted environment is one in which the
entire standard library is available, and in which main has a return
type of int. Examples are nearly everything except a kernel.
This is equivalent to `-fno-freestanding'.
-ffreestanding
Assert that compilation takes place in a freestanding environment. This
implies `-fno-builtin'. A freestanding environment
is one in which the standard library may not exist, and program startup may
not necessarily be at main. The most obvious example is an OS kernel.
This is equivalent to `-fno-hosted'.
-trigraphs
-traditional
extern declarations take effect globally even if they
are written inside of a function definition. This includes implicit
declarations of functions.
typeof, inline, signed, const
and volatile are not recognized. (You can still use the
alternative keywords such as __typeof__, __inline__, and
so on.)
unsigned short and unsigned char promote
to unsigned int.
register are preserved by
longjmp. Ordinarily, GNU C follows ANSI C: automatic variables
not declared volatile may be clobbered.
You may wish to use `-fno-builtin' as well as `-traditional' if your program uses names that are normally GNU C builtin functions for other purposes of its own.
You cannot use `-traditional' if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use `-traditional' on such systems to compile files that include any system headers.
The `-traditional' option also enables `-traditional-cpp', which is described next.
-traditional-cpp
__STDC__ is not defined when you use
`-traditional', but __GNUC__ is (since the GNU extensions
which __GNUC__ indicates are not affected by
`-traditional'). If you need to write header files that work
differently depending on whether `-traditional' is in use, by
testing both of these predefined macros you can distinguish four
situations: GNU C, traditional GNU C, other ANSI C compilers, and other
old C compilers. The predefined macro __STDC_VERSION__ is also
not defined when you use `-traditional'. See section `Standard Predefined Macros' in The C Preprocessor,
for more discussion of these and other predefined macros.
-fcond-mismatch
-funsigned-char
char be unsigned, like unsigned char.
Each kind of machine has a default for what char should
be. It is either like unsigned char by default or like
signed char by default.
Ideally, a portable program should always use signed char or
unsigned char when it depends on the signedness of an object.
But many programs have been written to use plain char and
expect it to be signed, or expect it to be unsigned, depending on the
machines they were written for. This option, and its inverse, let you
make such a program work with the opposite default.
The type char is always a distinct type from each of
signed char or unsigned char, even though its behavior
is always just like one of those two.
-fsigned-char
char be signed, like signed char.
Note that this is equivalent to `-fno-unsigned-char', which is the negative form of `-funsigned-char'. Likewise, the option `-fno-signed-char' is equivalent to `-funsigned-char'.
You may wish to use `-fno-builtin' as well as `-traditional' if your program uses names that are normally GNU C builtin functions for other purposes of its own.
You cannot use `-traditional' if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use `-traditional' on such systems to compile files that include any system headers.
-fsigned-bitfields
-funsigned-bitfields
-fno-signed-bitfields
-fno-unsigned-bitfields
signed or unsigned. By
default, such a bitfield is signed, because this is consistent: the
basic integer types such as int are signed types.
However, when `-traditional' is used, bitfields are all unsigned no matter what.
-fwritable-strings
Writing into string constants is a very bad idea; "constants" should be constant.
-fallow-single-precision
Traditional K&R C promotes all floating point operations to double precision, regardless of the sizes of the operands. On the architecture for which you are compiling, single precision may be faster than double precision. If you must use `-traditional', but want to use single precision operations when the operands are single precision, use this option. This option has no effect when compiling with ANSI or GNU C conventions (the default).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes the command-line options that are only meaningful
for C++ programs; but you can also use most of the GNU compiler options
regardless of what language your program is in. For example, you
might compile a file firstClass.C like this:
g++ -g -frepo -O -c firstClass.C |
In this example, only `-frepo' is an option meant only for C++ programs; you can use the other options with any language supported by GNU CC.
Here is a list of options that are only for compiling C++ programs:
-fno-access-control
-fcheck-new
operator new is non-null
before attempting to modify the storage allocated. The current Working
Paper requires that operator new never return a null pointer, so
this check is normally unnecessary.
An alternative to using this option is to specify that your
operator new does not throw any exceptions; if you declare it
`throw()', g++ will check the return value. See also `new
(nothrow)'.
-fconserve-space
main() has
completed, you may have an object that is being destroyed twice because
two definitions were merged.
This option is no longer useful on most targets, now that support has been added for putting variables into BSS without making them common.
-fdollars-in-identifiers
-fno-elide-constructors
-fexternal-templates
This option is deprecated.
-falt-external-templates
This option is deprecated.
-ffor-scope
-fno-for-scope
The default if neither flag is given to follow the standard, but to allow and give a warning for old-style code that would otherwise be invalid, or have different behavior.
-fno-gnu-keywords
classof, headof, signature,
sigof or typeof as a keyword, so that code can use these
words as identifiers. You can use the keywords __classof__,
__headof__, __signature__, __sigof__, and
__typeof__ instead. `-ansi' implies
`-fno-gnu-keywords'.
-fguiding-decls
This option implies `-fname-mangling-version-0', and will not work with other name mangling versions. Like all options that change the ABI, all C++ code, including libgcc.a must be built with the same setting of this option.
-fhandle-signatures
signature and sigof keywords for specifying
abstract types. The default (`-fno-handle-signatures') is not to
recognize them. See section Type Abstraction using Signatures.
-fhonor-std
namespace std as a namespace, instead of ignoring
it. For compatibility with earlier versions of g++, the compiler will,
by default, ignore namespace-declarations,
using-declarations, using-directives, and
namespace-names, if they involve std.
-fhuge-objects
This flag is not useful when compiling with -fvtable-thunks.
Like all options that change the ABI, all C++ code, including libgcc must be built with the same setting of this option.
-fmerge-templates
This flag is only supported on ELF targets.
-fno-implicit-templates
-fno-implicit-inline-templates
-finit-priority
-fno-implement-inlines
-fname-mangling-version-n
template <class T, class U> void foo(T t); |
Like all options that change the ABI, all C++ code, including libgcc must be built with the same setting of this option.
-foperator-names
and, bitand,
bitor, compl, not, or and xor as
synonyms for the symbols they refer to. `-ansi' implies
`-foperator-names'.
-fno-optional-diags
-fpermissive
-frepo
-fno-rtti
-fstrict-prototype
foo can take any combination of arguments, as
in C. `-pedantic' implies `-fstrict-prototype' unless
overridden with `-fno-strict-prototype'.
Specifying this option will also suppress implicit declarations of functions.
This flag no longer affects declarations with C++ linkage.
-fsquangle
-fno-squangle
Like all options that change the ABI, all C++ code, including libgcc.a must be built with the same setting of this option.
-ftemplate-depth-n
-fthis-is-variable
this. The incorporation of user-defined
free store management into C++ has made assignment to `this' an
anachronism. Therefore, by default it is invalid to assign to
this within a class member function; that is, GNU C++ treats
`this' in a member function of class X as a non-lvalue of
type `X *'. However, for backwards compatibility, you can make it
valid with `-fthis-is-variable'.
-fvtable-thunks
This option also enables a heuristic for controlling emission of vtables; if a class has any non-inline virtual functions, the vtable will be emitted in the translation unit containing the first one of those.
Like all options that change the ABI, all C++ code, including libgcc.a must be built with the same setting of this option.
-nostdinc++
In addition, these optimization, warning, and code generation options have meanings only for C++ programs:
-fno-default-inline
-Wctor-dtor-privacy (C++ only)
-Wnon-virtual-dtor (C++ only)
-Wreorder (C++ only)
struct A {
int i;
int j;
A(): j (0), i (1) { }
};
|
Here the compiler will warn that the member initializers for `i' and `j' will be rearranged to match the declaration order of the members.
The following `-W...' options are not affected by `-Wall'.
-Weffc++ (C++ only)
-Wno-deprecated (C++ only)
-Wno-non-template-friend (C++ only)
-Wold-style-cast (C++ only)
-Woverloaded-virtual (C++ only)
-Wno-pmf-conversions (C++ only)
-Wsign-promo (C++ only)
-Wsynth (C++ only)
struct A {
operator int ();
A& operator = (int);
};
main ()
{
A a,b;
a = b;
}
|
In this example, g++ will synthesize a default `A& operator = (const A&);', while cfront will use the user-defined `operator ='.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there may have been an error.
You can request many specific warnings with options beginning `-W', for example `-Wimplicit' to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning `-Wno-' to turn off warnings; for example, `-Wno-implicit'. This manual lists only one of the two forms, whichever is not the default.
These options control the amount and kinds of warnings produced by GNU CC:
-fsyntax-only
-pedantic
Valid ANSI C and ISO C++ programs should compile properly with or without this option (though a rare few will require `-ansi'). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected.
`-pedantic' does not cause warning messages for use of the
alternate keywords whose names begin and end with `__'. Pedantic
warnings are also disabled in the expression that follows
__extension__. However, only system header files should use
these escape routes; application programs should avoid them.
See section 3.35 Alternate Keywords.
This option is not intended to be useful; it exists only to satisfy pedants who would otherwise claim that GNU CC fails to support the ANSI standard.
Some users try to use `-pedantic' to check programs for strict ANSI C conformance. They soon find that it does not do quite what they want: it finds some non-ANSI practices, but not all--only those for which ANSI C requires a diagnostic.
A feature to report any failure to conform to ANSI C might be useful in some instances, but would require considerable additional work and would be quite different from `-pedantic'. We don't have plans to support such a feature in the near future.
-pedantic-errors
-w
-Wno-import
-Wchar-subscripts
char. This is a common cause
of error, as programmers often forget that this type is signed on some
machines.
-Wcomment
-Wformat
printf and scanf, etc., to make sure that
the arguments supplied have types appropriate to the format string
specified.
-Wimplicit-int
-Wimplicit-function-declaration
-Werror-implicit-function-declaration
-Wimplicit
-Wmain
-Wmultichar
-Wparentheses
Also warn about constructions where there may be confusion to which
if statement an else branch belongs. Here is an example of
such a case:
{
if (a)
if (b)
foo ();
else
bar ();
}
|
In C, every else branch belongs to the innermost possible if
statement, which in this example is if (b). This is often not
what the programmer expected, as illustrated in the above example by
indentation the programmer chose. When there is the potential for this
confusion, GNU C will issue a warning when this flag is specified.
To eliminate the warning, add explicit braces around the innermost
if statement so there is no way the else could belong to
the enclosing if. The resulting code would look like this:
{
if (a)
{
if (b)
foo ();
else
bar ();
}
}
|
-Wreturn-type
int. Also warn about any return statement with no
return-value in a function whose return-type is not void.
-Wswitch
switch statement has an index of enumeral type
and lacks a case for one or more of the named codes of that
enumeration. (The presence of a default label prevents this
warning.) case labels outside the enumeration range also
provoke warnings when this option is used.
-Wtrigraphs
-Wunused
In order to get a warning about an unused function parameter, you must specify both `-W' and `-Wunused'.
To suppress this warning for an expression, simply cast it to void. For unused variables, parameters and labels, use the `unused' attribute (see section 3.29 Specifying Attributes of Variables).
-Wuninitialized
These warnings are possible only in optimizing compilation, because they require data flow information that is computed only when optimizing. If you don't specify `-O', you simply won't get these warnings.
These warnings occur only for variables that are candidates for
register allocation. Therefore, they do not occur for a variable that
is declared volatile, or whose address is taken, or whose size
is other than 1, 2, 4 or 8 bytes. Also, they do not occur for
structures, unions or arrays, even when they are in registers.
Note that there may be no warning about a variable that is used only to compute a value that itself is never used, because such computations may be deleted by data flow analysis before the warnings are printed.
These warnings are made optional because GNU CC is not smart enough to see all the reasons why the code might be correct despite appearing to have an error. Here is one example of how this can happen:
{
int x;
switch (y)
{
case 1: x = 1;
break;
case 2: x = 4;
break;
case 3: x = 5;
}
foo (x);
}
|
If the value of y is always 1, 2 or 3, then x is
always initialized, but GNU CC doesn't know this. Here is
another common case:
{
int save_y;
if (change_y) save_y = y, y = new_y;
...
if (change_y) y = save_y;
}
|
This has no bug because save_y is used only if it is set.
Some spurious warnings can be avoided if you declare all the functions
you use that never return as noreturn. See section 3.23 Declaring Attributes of Functions.
-Wunknown-pragmas
-Wall
The following `-W...' options are not implied by `-Wall'. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning.
-W
longjmp. These warnings as well are possible only in
optimizing compilation.
The compiler sees only the calls to setjmp. It cannot know
where longjmp will be called; in fact, a signal handler could
call it at any point in the code. As a result, you may get a warning
even when there is in fact no problem because longjmp cannot
in fact be called at the place which would cause a problem.
foo (a)
{
if (a > 0)
return a;
}
|
static are not the first things in
a declaration. According to the C Standard, this usage is obsolescent.
x.h:
struct s { int f, g; };
struct t { struct s h; int i; };
struct t x = { 1, 2, 3 };
|
x.h would be implicitly initialized to zero:
struct s { int f, g, h; };
struct s x = { 3, 4 };
|
-Wtraditional
switch statement has an operand of type long.
static function declaration follows a static one.
This construct is not accepted by some traditional C compilers.
-Wundef
-Wshadow
-Wid-clash-len
-Wlarger-than-len
-Wpointer-arith
void. GNU C assigns these types a size of 1, for
convenience in calculations with void * pointers and pointers
to functions.
-Wbad-function-cast
int malloc() is cast to anything *.
-Wcast-qual
const char * is cast
to an ordinary char *.
-Wcast-align
char * is cast to
an int * on machines where integers can only be accessed at
two- or four-byte boundaries.
-Wwrite-strings
const char[length] so that
copying the address of one into a non-const char *
pointer will get a warning. These warnings will help you find at
compile time code that can try to write into a string constant, but
only if you have been very careful about using const in
declarations and prototypes. Otherwise, it will just be a nuisance;
this is why we did not make `-Wall' request these warnings.
-Wconversion
Also, warn if a negative integer constant expression is implicitly
converted to an unsigned type. For example, warn about the assignment
x = -1 if x is unsigned. But do not warn about explicit
casts like (unsigned) -1.
-Wsign-compare
-Waggregate-return
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
-Wmissing-noreturn
noreturn.
Note these are only possible candidates, not absolute ones. Care should
be taken to manually verify functions actually do not ever return before
adding the noreturn attribute, otherwise subtle code generation
bugs could be introduced.
-Wredundant-decls
-Wnested-externs
extern declaration is encountered within an function.
-Winline
-Wlong-long
-Werror
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU CC has various special options that are used for debugging either your program or GCC:
-g
On most systems that use stabs format, `-g' enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use `-gstabs+', `-gstabs', `-gxcoff+', `-gxcoff', `-gdwarf-1+', or `-gdwarf-1' (see below).
Unlike most other C compilers, GNU CC allows you to use `-g' with `-O'. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops.
Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.
The following options are useful when GNU CC is generated with the capability for more than one debugging format.
-ggdb
-gstabs
-gstabs+
-gcoff
-gxcoff
-gxcoff+
-gdwarf
-gdwarf+
-gdwarf-2
-glevel
-ggdblevel
-gstabslevel
-gcofflevel
-gxcofflevel
-gdwarflevel
-gdwarf-2level
Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, but no information about local variables and no line numbers.
Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use `-g3'.
-p
prof. You must use this option when compiling
the source files you want data about, and you must also use it when
linking.
-pg
gprof. You must use this option when compiling
the source files you want data about, and you must also use it when
linking.
-a
This data could be analyzed by a program like tcov. Note,
however, that the format of the data is not what tcov expects.
Eventually GNU gprof should be extended to process this data.
-Q
-ax
You can examine different profiling aspects without recompilation. Your executable will read a list of function names from file `bb.in'. Profiling starts when a function on the list is entered and stops when that invocation is exited. To exclude a function from profiling, prefix its name with `-'. If a function name is not unique, you can disambiguate it by writing it in the form `/path/filename.d:functionname'. Your executable will write the available paths and filenames in file `bb.out'.
Several function names have a special meaning:
__bb_jumps__
__bb_hidecall__
__bb_showret__
__bb_trace__
PATH. On systems without the `popen'
function, the file will be named `bbtrace' and will not be
compressed. Profiling for even a few seconds on these systems
will produce a very large file. Note: __bb_hidecall__ and
__bb_showret__ will not affect the sequence written to
`bbtrace.gz'.
Here's a short example using different profiling parameters
in file `bb.in'. Assume function foo consists of basic blocks
1 and 2 and is called twice from block 3 of function main. After
the calls, block 3 transfers control to block 4 of main.
With __bb_trace__ and main contained in file `bb.in',
the following sequence of blocks is written to file `bbtrace.gz':
0 3 1 2 1 2 4. The return from block 2 to block 3 is not shown, because
the return is to a point inside the block and not to the top. The
block address 0 always indicates, that control is transferred
to the trace from somewhere outside the observed functions. With
`-foo' added to `bb.in', the blocks of function
foo are removed from the trace, so only 0 3 4 remains.
With __bb_jumps__ and main contained in file `bb.in',
jump frequencies will be written to file `bb.out'. The
frequencies are obtained by constructing a trace of blocks
and incrementing a counter for every neighbouring pair of blocks
in the trace. The trace 0 3 1 2 1 2 4 displays the following
frequencies:
Jump from block 0x0 to block 0x3 executed 1 time(s) Jump from block 0x3 to block 0x1 executed 1 time(s) Jump from block 0x1 to block 0x2 executed 2 time(s) Jump from block 0x2 to block 0x1 executed 1 time(s) Jump from block 0x2 to block 0x4 executed 1 time(s) |
With __bb_hidecall__, control transfer due to call instructions
is removed from the trace, that is the trace is cut into three parts: 0
3 4, 0 1 2 and 0 1 2. With __bb_showret__, control transfer due
to return instructions is added to the trace. The trace becomes: 0 3 1
2 3 1 2 3 4. Note, that this trace is not the same, as the sequence
written to `bbtrace.gz'. It is solely used for counting jump
frequencies.
-fprofile-arcs
Since not every arc in the program must be instrumented, programs
compiled with this option run faster than programs compiled with
`-a', which adds instrumentation code to every basic block in the
program. The tradeoff: since gcov does not have
execution counts for all branches, it must start with the execution
counts for the instrumented branches, and then iterate over the program
flow graph until the entire graph has been solved. Hence, gcov
runs a little more slowly than a program which uses information from
`-a'.
`-fprofile-arcs' also makes it possible to estimate branch probabilities, and to calculate basic block execution counts. In general, basic block execution counts do not give enough information to estimate all branch probabilities. When the compiled program exits, it saves the arc execution counts to a file called `sourcename.da'. Use the compiler option `-fbranch-probabilities' (see section Options that Control Optimization) when recompiling, to optimize using estimated branch probabilities.
-ftest-coverage
gcov code-coverage utility.
The data file names begin with the name of your source file:
sourcename.bb
gcov uses to
associate basic block execution counts with line numbers.
sourcename.bbg
gcov
to reconstruct the program flow graph, so that it can compute all basic
block and arc execution counts from the information in the
sourcename.da file (this last file is the output from
`-fprofile-arcs').
-Q
-dletters
-fdump-unnumbered
-fpretend-float
-save-temps
-print-file-name=library
-print-prog-name=program
-print-libgcc-file-name
This is useful when you use `-nostdlib' or `-nodefaultlibs' but you do want to link with `libgcc.a'. You can do
gcc -nostdlib files... `gcc -print-libgcc-file-name` |
-print-search-dirs
This is useful when gcc prints the error message `installation problem, cannot exec cpp: No such file or directory'. To resolve this you either need to put `cpp' and the other compiler components where gcc expects to find them.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options control various sorts of optimizations:
-O
-O1
Without `-O', the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.
Without `-O', the compiler only allocates variables declared
register in registers. The resulting compiled code is a little
worse than produced by PCC without `-O'.
With `-O', the compiler tries to reduce code size and execution time.
When you specify `-O', the compiler turns on `-fthread-jumps' and `-fdefer-pop' on all machines. The compiler turns on `-fdelayed-branch' on machines that have delay slots, and `-fomit-frame-pointer' on machines that can support debugging even without a frame pointer. On some machines the compiler also turns on other flags.
-O2
`-O2' turns on all optional optimizations except for loop unrolling and function inlining. It also turns on the `-fforce-mem' option on all machines and frame pointer elimination on machines where doing so does not interfere with debugging.
-O3
-O0
-Os
If you use multiple `-O' options, with or without level numbers, the last such option is the one that is effective.
Options of the form `-fflag' specify machine-independent flags. Most flags have both positive and negative forms; the negative form of `-ffoo' would be `-fno-foo'. In the table below, only one of the forms is listed--the one which is not the default. You can figure out the other form by either removing `no-' or adding it.
-ffloat-store
This option prevents undesirable excess precision on machines such as
the 68000 where the floating registers (of the 68881) keep more
precision than a double is supposed to have. Similarly for the
x86 architecture. For most programs, the excess precision does only
good, but a few programs rely on the precise definition of IEEE floating
point. Use `-ffloat-store' for such programs, after modifying
them to store all pertinent intermediate computations into variables.
-fno-default-inline
-fno-defer-pop
-fforce-mem
-fforce-addr
-fomit-frame-pointer
On some machines, such as the Vax, this flag has no effect, because
the standard calling sequence automatically handles the frame pointer
and nothing is saved by pretending it doesn't exist. The
machine-description macro FRAME_POINTER_REQUIRED controls
whether a target machine supports this flag. See section `Register Usage' in Using and Porting GCC.
-fno-inline
inline keyword. Normally this option
is used to keep the compiler from expanding any functions inline.
Note that if you are not optimizing, no functions can be expanded inline.
-finline-functions
If all calls to a given function are integrated, and the function is
declared static, then the function is normally not output as
assembler code in its own right.
-finline-limit-n
Note: pseudo instruction represents, in this particular context, an abstract measurement of function's size. In no way, it represents a count of assembly instructions and as such its exact meaning might change from one release to an another.
-fkeep-inline-functions
static, nevertheless output a separate run-time
callable version of the function. This switch does not affect
extern inline functions.
-fkeep-static-consts
static const when optimization isn't turned
on, even if the variables aren't referenced.
GNU CC enables this option by default. If you want to force the compiler to check if the variable was referenced, regardless of whether or not optimization is turned on, use the `-fno-keep-static-consts' option.
-fno-function-cse
This option results in less efficient code, but some strange hacks that alter the assembler output may be confused by the optimizations performed when this option is not used.
-ffast-math
sqrt
function are non-negative numbers and that no floating-point values
are NaNs.
This option should never be turned on by any `-O' option since it can result in incorrect output for programs which depend on an exact implementation of IEEE or ANSI rules/specifications for math functions.
The following options control specific optimizations. The `-O2' option turns on all of these optimizations except `-funroll-loops' and `-funroll-all-loops'. On most machines, the `-O' option turns on the `-fthread-jumps' and `-fdelayed-branch' options, but specific machines may handle it differently.
You can use the following flags in the rare cases when "fine-tuning" of optimizations to be performed is desired.
-fstrength-reduce
-fthread-jumps
-fcse-follow-jumps
if statement with an
else clause, CSE will follow the jump when the condition
tested is false.
-fcse-skip-blocks
if statement with no else clause,
`-fcse-skip-blocks' causes CSE to follow the jump around the
body of the if.
-frerun-cse-after-loop
-frerun-loop-opt
-fgcse
-fexpensive-optimizations
-foptimize-register-moves
-fregmove
Note -fregmove and -foptimize-register-moves are the same
optimization.
-fdelayed-branch
-fschedule-insns
-fschedule-insns2
-ffunction-sections
-fdata-sections
Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. HPPA processors running HP-UX and Sparc processors running Solaris 2 have linkers with such optimizations. Other systems using the ELF object format as well as AIX may have these optimizations in the future.
Only use these options when there are significant benefits from doing
so. When you specify these options, the assembler and linker will
create larger object and executable files and will also be slower.
You will not be able to use gprof on all systems if you
specify this option and you may have problems with debugging if
you specify both this option and `-g'.
-fcaller-saves
This option is always enabled by default on certain machines, usually those which have no call-preserved registers to use instead.
For all machines, optimization level 2 and higher enables this flag by default.
-funroll-loops
-funroll-all-loops
-fmove-all-movables
-freduce-all-givs
Note: When compiling programs written in Fortran, `-fmove-all-moveables' and `-freduce-all-givs' are enabled by default when you use the optimizer.
These options may generate better or worse code; results are highly dependent on the structure of loops within the source code.
These two options are intended to be removed someday, once they have helped determine the efficacy of various approaches to improving loop optimizations.
Please let us (egcs@egcs.cygnus.com and fortran@gnu.org)
know how use of these options affects
the performance of your production code.
We're very interested in code that runs slower
when these options are enabled.
-fno-peephole
-fbranch-probabilities
gcc), you can compile it a second time using
`-fbranch-probabilities', to improve optimizations based on
guessing the path a branch might take.
-fstrict-aliasing
unsigned int can alias an int, but not a
void* or a double. A character type may alias any other
type.
Pay special attention to code like this:
union a_union {
int i;
double d;
};
int f() {
a_union t;
t.d = 3.0;
return t.i;
}
|
int f() {
a_union t;
int* ip;
t.d = 3.0;
ip = &t.i;
return *ip;
}
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options control the C preprocessor, which is run on each C source file before actual compilation.
If you use the `-E' option, nothing is done except preprocessing. Some of these options make sense only together with `-E' because they