Chapter 1. Compiler Options

Table of Contents
1.1. Option Summary
1.2. Options Controlling the Kind of Output
1.3. Compiling C++ Programs
1.4. Options Controlling C Dialect
1.5. Options Controlling C++ Dialect
1.6. Options to Request or Suppress Warnings
1.7. Options for Debugging Your Program or the compiler
1.8. Options that Control Optimization
1.9. Options Controlling the Preprocessor
1.10. Passing Options to the Assembler
1.11. Options for Linking
1.12. Options for Directory Search
1.13. Hardware Models and Configurations
1.14. Options for Code Generation Conventions
1.15. Environment Variables Affecting the Compiler
1.16. Running Protoize

When you run the compiler, it usually performs all the necessary steps to convert source code into object code. For source files written in C or C++ the necessary steps are as follows:

  1. Pre-processing

  2. Compilation

  3. Assembly

  4. Linking

The “overall” options allow you to stop this process before th final step. For example, the -c option says not to run the linker. Then the output consists of object code 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 GCC 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 1.3, for a summary of special options for compiling C++ programs.

The gcc program accepts options and file names as operands. Many options have multi-letter 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.

1.1. Option Summary

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

Overall Options

See Section 1.2.

-c  -S  -E  -o file  -pipe  -v  -x language
C Language Options

See Section 1.4.

-ansi  -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
C++ Language Options

See Section 1.5.

-fall-virtual  -fdollars-in-identifiers  -felide-constructors
-fenum-int-equiv  -fexternal-templates  -ffor-scope  -fno-for-scope
-fhandle-signatures  -fmemoize-lookups  -fname-mangling-version-n
-fno-default-inline  -fno-gnu-keywords -fnonnull-objects
-fguiding-decls -foperator-names  -fstrict-prototype
-fthis-is-variable -ftemplate-depth-n  -nostdinc++
-traditional  +en
Warning Options

See Section 1.6.

-fsyntax-only  -pedantic  -pedantic-errors
-w  -W  -Wall  -Waggregate-return  -Wbad-function-cast
-Wcast-align  -Wcast-qual  -Wchar-subscript  -Wcomment
-Wconversion  -Werror  -Wformat
-Wid-clash-len  -Wimplicit -Wimplicit-int
-Wimplicit-function-declarations -Wimport  -Winline
-Wlarger-than-len  -Wmain  -Wmissing-declarations
-Wmissing-prototypes  -Wnested-externs
-Wno-import  -Wold-style-cast  -Woverloaded-virtual  -Wparentheses
-Wpointer-arith  -Wredundant-decls  -Wreorder  -Wreturn-type i
-Wshadow -Wsign-compare  -Wstrict-prototypes  -Wswitch  -Wsynth
-Wtemplate-debugging  -Wtraditional  -Wtrigraphs
-Wundef  -Wuninitialized  -Wunused  -Wwrite-strings
Debugging Options

See Section 1.7.

-a  -ax  -dletters  -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
Optimization Options

See Section 1.8.

-fbranch-probabilities
-fcaller-saves  -fcse-follow-jumps  -fcse-skip-blocks
-fdelayed-branch   -fexpensive-optimizations
-ffast-math  -ffloat-store  -fforce-addr  -fforce-mem
-ffunction-sections  -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  -O0  -O1  -O2  -O3
Preprocessor Options

See Section 1.9.

-Aquestion(answer)  -C  -dD  -dM  -dN
-Dmacro[=defn]  -E  -H
-idirafter dir
-include file  -imacros file
-iprefix file  -iwithprefix dir
-iwithprefixbefore dir  -isystem dir
-M  -MD  -MM  -MMD  -MG  -nostdinc  -P  -trigraphs
-undef  -Umacro  -Wp,option
Assembler Option

See Section 1.10.

-Wa,option
Linker Options

See Section 1.11.

object-file-name  -llibrary
-nostartfiles  -nodefaultlibs  -nostdlib
-s  -static  -shared  -symbolic
-Wl,option  -Xlinker option
-u symbol
Directory Options

See Section 1.12.

-Bprefix  -Idir  -I-  -Ldir  -specs=file
Machine Dependent Options

See Section 1.13.2.

M1750 Options
-mmmu -mno-mmu
-mb1 -mb2 -mb3
-mno-b1 -mno-b2 -mno-b3
ERC32 Options
-malign-jumps=num  -malign-loops=num
-malign-functions=num
-mapp-regs  -mepilogue
-mfpu  -mhard-float -mno-fpu -msoft-float
-mno-app-regs  -mno-epilogue
-mno-unaligned-doubles
-mv7 -mcba -mcca -mcda -mcpu=cpu