Go to the previous, next section.

GNU CC Command Options

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.

@xref{Invoking options for compiling C++ programs.}++,,Compiling C++ Programs}, for a summary of special

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.

Option Summary

Here is a summary of all the options, grouped by type. Explanations are in the following sections.

Overall Options
See section Options Controlling the Kind of Output.
-c  -S  -E  -o file  -pipe  -v  -x language 

C Language Options
See section Options Controlling C Dialect.
-ansi  -fcond-mismatch  -fno-asm  -fno-builtin
-fsigned-bitfields  -fsigned-char 
-funsigned-bitfields  -funsigned-char  -fwritable-strings
-traditional  -traditional-cpp  -trigraphs

C++ Language Options
@xref{
}++ Dialect Options,,Options Controlling C++ Dialect}.
-fall-virtual  -fdollars-in-identifiers
-felide-constructors  -fenum-int-equiv
-fexternal-templates  -fmemoize-lookups
-fno-strict-prototype  -fnonnull-objects
-fthis-is-variable  -nostdinc++

Warning Options
See section Options to Request or Suppress Warnings.
-fsyntax-only  -pedantic  -pedantic-errors
-w  -W  -Wall  -Waggregate-return  -Wcast-align  
-Wcast-qual  -Wchar-subscript  -Wcomment  -Wconversion
-Wenum-clash  -Werror  -Wformat  -Wid-clash-len
-Wimplicit  -Wimport  -Winline  -Wmissing-prototypes
-Wnested-externs  -Woverloaded-virtual  -Wparentheses
-Wpointer-arith  -Wredundant-decls  -Wreturn-type
-Wshadow  -Wstrict-prototypes  -Wswitch
-Wtemplate-debugging  -Wtraditional  -Wtrigraphs
-Wuninitialized  -Wunused  -Wwrite-strings

Debugging Options
See section Options for Debugging Your Program or GNU CC.
-a  -dletters  -fpretend-float 
-g  -glevel -ggdb  -gdwarf -gdwarf+
-gstabs  -gstabs+  -gcoff -gxcoff  -gxcoff+
-p  -pg  -save-temps  -print-libgcc-file-name

Optimization Options
See section Options That Control Optimization.
-fcaller-saves  -fcse-follow-jumps  -fcse-skip-blocks
-fdelayed-branch   -fexpensive-optimizations  
-ffast-math  -ffloat-store  -fforce-addr  -fforce-mem
-finline-functions  -fkeep-inline-functions  
-fno-default-inline  -fno-defer-pop  -fno-function-cse
-fno-inline  -fno-peephole  -fomit-frame-pointer  
-frerun-cse-after-loop  -fschedule-insns  
-fschedule-insns2  -fstrength-reduce  -fthread-jumps 
-funroll-all-loops  -funroll-loops
-O  -O2

Preprocessor Options
See section Options Controlling the Preprocessor.
-Aassertion  -C  -dD  -dM  -dN
-Dmacro[=defn]  -E  -H
-idirafter dir
-include file  -imacros file
-iprefix file  -iwithprefix dir
-iwithprefixbefore dir
-M  -MD  -MM  -MMD  -nostdinc  -P  -trigraphs  -Umacro

Assembler Option
See section Passing Options to the Assembler.
-Wa,option

Linker Options
See section Options for Linking.
object-file-name
-llibrary  -nostartfiles  -nostdlib  
-static  -shared  -symbolic  
-Wl,option  -Xlinker option
-u symbol

Directory Options
See section Options for Directory Search.
-Bprefix  -Idir  -I-  -Ldir

Target Options
See section Specifying Target Machine and Compiler Version.
-b machine  -V version

Machine Dependent Options
See section Hardware Models and Configurations.
M680x0 Options
-m68000  -m68020  -m68020-40  -m68030  -m68040  -m68881  
-mbitfield  -mc68000  -mc68020  -mfpa  -mnobitfield  
-mrtd  -mshort  -msoft-float 

VAX Options
-mg  -mgnu  -munix

SPARC Options
-mepilogue  -mfpu  -mhard-float
-mno-fpu  -mno-epilogue  -msoft-float
-msparclite  -mv8

Convex Options
-mc1  -mc2  -mc32  -mc34  -mc38
-margcount  -mnoargcount
-mlong32  -mlong64
-mbolatile-cache  -mvolatile-nocache

AMD29K Options 
-m29000  -m29050  -mbw  -mdw  -mkernel-registers
-mlarge  -mnbw  -mnodw  -mnormal  -msmall  -mstack-check
-muser-registers

M88K Options
-m88000  -m88100  -m88110  -mbig-pic  
-mcheck-zero-division  -mhandle-large-shift 
-midentify-revision  -mno-check-zero-division 
-mno-ocs-debug-info  -mno-ocs-frame-position 
-mno-optimize-arg-area  -mno-serialize-volatile
-mno-underscores  -mocs-debug-info
-mocs-frame-position  -moptimize-arg-area
-mserialize-volatile  -mshort-data-num  -msvr3 
-msvr4  -mtrap-large-shift  -muse-div-instruction 
-mversion-03.00  -mwarn-passed-structs

RS/6000 Options and PowerPC
-mcpu=cpu type
-mpower -mno-power -mpower2 -pno-power2
-mpowerpc -mno-powerpc -mpowerpcsqr -mno-powerpcsqr
-mpowerpc64 -mno-powerpc64
-mnew-mnemonics -mno-new-mnemonics
-mnormal-toc   -mminimal-toc  -mno-fop-in-toc

RT Options
-mcall-lib-mul  -mfp-arg-in-fpregs  -mfp-arg-in-gregs
-mfull-fp-blocks  -mhc-struct-return  -min-line-mul
-mminimum-fp-blocks  -mnohc-struct-return

MIPS Options
-mcpu=cpu  type  -mips2  -mips3  -mint64
-mlong64  -mlonglong128  -mmips-as  -mgas  -mrnames
-mno-rnames  -mgpopt  -mno-gpopt  -mstats  -mno-stats
-mmemcpy  -mno-memcpy  -mno-mips-tfile  -mmips-tfile
-msoft-float  -mhard-float  -mabicalls  -mno-abicalls
-mhalf-pic  -mno-half-pic -mlong-calls -mno-long-calls
-G  num  -nocpp

i386 Options
-m486  -mno-486  -msoft-float  -msvr3-shlib  -mieee-fp
-mno-fp-ret-in-387

HPPA Options
-mpa-risc-1-0
-mpa-risc-1-1
-mlong-calls
-mdisable-fpregs
-mdisable-indexing
-mtrailing-colon

Intel 960 Options
-mcpu type
-mnumerics  -msoft-float
-mcode-align  -mno-code-align
-mleaf-procedures  -mno-leaf-procedures
-mtail-call  -mno-tail-call
-mcomplex-addr  -mno-complex-addr
-mclean-linkage  -mno-clean-linkage
-mic-compat  -mic2.0-compat  -mic3.0-compat
-masm-compat  -mintel-asm
-mstrict-align  -mno-strict-align
-mold-align  -mno-old-align

DEC Alpha Options
-mfp-regs  -mno-fp-regs  -mno-soft-float
-msoft-float

Clipper Options
-mc300 -mc400

System V Options
-G  -Qy  -Qn  -YP,paths  -Ym,dir

Code Generation Options
See section Options for Code Generation Conventions.
-fcall-saved-reg  -fcall-used-reg 
-ffixed-reg  -finhibit-size-directive 
-fno-common  -fno-ident
-fno-gnu-linker  -fpcc-struct-return  -fpic  -fPIC 
-freg-struct-return  -fshared-data  -fshort-enums
-fshort-double  -fvolatile  -fvolatile-global
-fverbose-asm

Options Controlling the Kind of Output

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
C source code which must be preprocessed.

file.i
C source code which should not be preprocessed.

file.ii
C++ source code which should not be preprocessed.

file.m
Objective-C source code. Note that you must link with the library `libobjc.a' to make an Objective-C program work.

file.h
C header file (not to be compiled or linked).

file.cc
file.cxx
file.C
C++ source code which must be preprocessed. Note that in `.cxx', the last two letters must both be literally `x'. Likewise, `.C' refers to a literal capital C.

file.s
Assembler code.

file.S
Assembler code which must be preprocessed.

other
An object file to be fed straight into linking. Any file name with no recognized suffix is treated this way.

You can specify the input language explicitly with the `-x' option:

-x language
Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next `-x' option. Possible values for language are:
c  objective-c  c++
c-header  cpp-output  c++-cpp-output
assembler  assembler-with-cpp

-x none
Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if `-x' has not been used at all).

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.

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
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.

-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.

Compiling C++ Programs

C++ source files conventionally use one of the suffixes `.C', `.cc', 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 shell script that calls GNU CC with the default language set to C++, and automatically specifies linking against the GNU class library libg++. (1) 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. @xref{ explanations of options that are meaningful only for C++ programs.}++ Dialect Options,,Options Controlling C++ Dialect}, for

Options Controlling C Dialect

The following options control the dialect of C (or languages derived from C, such as C++ and Objective C) that the compiler accepts:

-ansi
Support all ANSI standard C programs.

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 disallows `$' as part of identifiers.

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 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 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.

-fno-asm
Do not recognize asm, inline or typeof as a keyword. These words may then be used as identifiers. You can use the keywords __asm__, __inline__ and __typeof__ instead. `-ansi' implies `-fno-asm'.

-fno-builtin
Don't recognize builtin functions that do not begin with two leading underscores. Currently, the functions affected include 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.

-trigraphs
Support ANSI C trigraphs. You don't want to know about this brain-damage. The `-ansi' option implies `-trigraphs'.

-traditional
Attempt to support some aspects of traditional C compilers. Specifically:

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.

-traditional-cpp
Attempt to support some aspects of traditional C preprocessors. This includes the last three items in the table immediately above, but none of the other effects of `-traditional'.

-fcond-mismatch
Allow conditional expressions with mismatched types in the second and third arguments. The value of such an expression is void.

-funsigned-char
Let the type 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
Let the type 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'.

-fsigned-bitfields
-funsigned-bitfields
-fno-signed-bitfields
-fno-unsigned-bitfields
These options control whether a bitfield is signed or unsigned, when the declaration does not use either 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
Store string constants in the writable data segment and don't uniquize them. This is for compatibility with old programs which assume they can write into string constants. The option `-traditional' also has this effect.

Writing into string constants is a very bad idea; "constants" should be constant.

-fallow-single-precision
Do not promote single precision math operations to double precision, even when compiling with `-traditional'.

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).

Options Controlling C++ Dialect

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 -felide-constructors -O -c firstClass.C

In this example, only `-felide-constructors' 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:

-fall-virtual
Treat all possible member functions as virtual, implicitly. All member functions (except for constructor functions and new or delete member operators) are treated as virtual functions of the class where they appear.

This does not mean that all calls to these member functions will be made through the internal table of virtual functions. Under some circumstances, the compiler can determine that a call to a given virtual function can be made directly; in these cases the calls are direct in any case.

-fdollars-in-identifiers
Accept `$' in identifiers. You can also explicitly prohibit use of `$' with the option `-fno-dollars-in-identifiers'. (GNU C++ allows `$' by default on some target systems but not others.) Traditional C allowed the character `$' to form part of identifiers. However, ANSI C and C++ forbid `$' in identifiers.

-felide-constructors
Elide constructors when this seems plausible. With this option, GNU C++ initializes y directly from the call to foo without going through a temporary in the following code:

A foo ();
A y = foo ();

Without this option, GNU C++ (1) initializes y by calling the appropriate constructor for type A; (2) assigns the result of foo to a temporary; and, finally, (3) replaces the initial value of y with the temporary.

The default behavior (`-fno-elide-constructors') is specified by the draft ANSI C++ standard. If your program's constructors have side effects, `-felide-constructors' can change your program's behavior, since some constructor calls may be omitted.

-fenum-int-equiv
Permit implicit conversion of int to enumeration types. Normally GNU C++ allows conversion of enum to int, but not the other way around.

-fexternal-templates
Produce smaller code for template declarations, by generating only a single copy of each template function where it is defined. To use this option successfully, you must also mark all files that use templates with either `#pragma implementation' (the definition) or `#pragma interface' (declarations). @xref{ Interface,,Declarations and Definitions in One Header}, for more discussion of these pragmas.

When your code is compiled with `-fexternal-templates', all template instantiations are external. You must arrange for all necessary instantiations to appear in the implementation file; you can do this with a typedef that references each instantiation needed. Conversely, when you compile using the default option `-fno-external-templates', all template instantiations are explicitly internal.

You do not need to specify `-fexternal-templates' when compiling a file that does not define and instantiate templates used in other files, even if your file uses templates defined in other files that are compiled with `-fexternal-templates'. The only side effect is an increase in object size for each file that you compile without `-fexternal-templates'.

-fmemoize-lookups
-fsave-memoized
Use heuristics to compile faster. These heuristics are not enabled by default, since they are only effective for certain input files. Other input files compile more slowly.

The first time the compiler must build a call to a member function (or reference to a data member), it must (1) determine whether the class implements member functions of that name; (2) resolve which member function to call (which involves figuring out what sorts of type conversions need to be made); and (3) check the visibility of the member function to the caller. All of this adds up to slower compilation. Normally, the second time a call is made to that member function (or reference to that data member), it must go through the same lengthy process again. This means that code like this:

cout << "This " << p << " has " << n << " legs.\n";

makes six passes through all three steps. By using a software cache, a "hit" significantly reduces this cost. Unfortunately, using the cache introduces another layer of mechanisms which must be implemented, and so incurs its own overhead. `-fmemoize-lookups' enables the software cache.

Because access privileges (visibility) to members and member functions may differ from one function context to the next, G++ may need to flush the cache. With the `-fmemoize-lookups' flag, the cache is flushed after every function that is compiled. The `-fsave-memoized' flag enables the same software cache, but when the compiler determines that the context of the last function compiled would yield the same access privileges of the next function to compile, it preserves the cache. This is most helpful when defining many member functions for the same class: with the exception of member functions which are friends of other classes, each member function has exactly the same access privileges as every other, and the cache need not be flushed.

-fno-strict-prototype
Treat a function declaration with no arguments, such as `int foo ();', as C would treat it--as saying nothing about the number of arguments or their types. Normally, such a declaration in C++ means that the function foo takes no arguments.

-fnonnull-objects
Assume that objects reached through references are not null.

Normally, GNU C++ makes conservative assumptions about objects reached through references. For example, the compiler must check that a is not null in code like the following:

obj &a = g ();
a.f (2);

Checking that references of this sort have non-null values requires extra code, however, and it is unnecessary for many programs. You can use `-fnonnull-objects' to omit the checks for null, if your program doesn't require checking.

-fthis-is-variable
Permit assignment to 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 the type of `this' in a member function of class X to be `X *const'. However, for backwards compatibility, you can make it valid with `-fthis-is-variable'.

-nostdinc++
Do not search for header files in the standard directories specific to C++, but do still search the other standard directories. (This option is used when building libg++.)

-traditional
For C++ programs (in addition to the effects that apply to both C and C++), this has the same effect as `-fthis-is-variable'. See section Options Controlling C Dialect.

In addition, these optimization, warning, and code generation options have meanings only for C++ programs:

-fno-default-inline
Do not assume `inline' for functions defined inside a class scope. See section Options That Control Optimization.

-Wenum-clash
-Woverloaded-virtual
-Wtemplate-debugging
Warnings that apply only to C++ programs. See section Options to Request or Suppress Warnings.

+en
Control how virtual function definitions are used, in a fashion compatible with cfront 1.x. See section Options for Code Generation Conventions.

Options to Request or Suppress Warnings

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
Check the code for syntax errors, but don't do anything beyond that.

-w
Inhibit all warning messages.

-Wno-import
Inhibit warning messages about the use of `#import'.

-pedantic
Issue all the warnings demanded by strict ANSI standard C; reject all programs that use forbidden extensions.

Valid ANSI standard 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 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