Next:Compiling C++ Programs, Previous:Option Summary, Up:GCC Command Options [Contents][Index]
Compilation can involve up to four stages: preprocessing, compilationproper, assembly and linking, always in that order. GCC is capable ofpreprocessing and compiling several files either into severalassembler input files, or into one assembler input file; then eachassembler input file produces an object file, and linking combines allthe 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 ofcompilation is done:
file.cC source code that must be preprocessed.
file.iC source code that should not be preprocessed.
file.iiC++ source code that should not be preprocessed.
file.mObjective-C source code. Note that you must link with thelibobjclibrary to make an Objective-C program work.
file.miObjective-C source code that should not be preprocessed.
file.mmfile.MObjective-C++ source code. Note that you must link with thelibobjclibrary to make an Objective-C++ program work. Note that ‘.M’ refersto a literal capital M.
file.miiObjective-C++ source code that should not be preprocessed.
file.hC, C++, Objective-C or Objective-C++ header file to be turned into aprecompiled header (default), or C, C++ header file to be turned into anAda spec (via the-fdump-ada-spec switch).
file.ccfile.cpfile.cxxfile.cppfile.CPPfile.c++file.CC++ source code that 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.mmfile.MObjective-C++ source code that must be preprocessed.
file.miiObjective-C++ source code that should not be preprocessed.
file.hhfile.Hfile.hpfile.hxxfile.hppfile.HPPfile.h++file.tccC++ header file to be turned into a precompiled header or Ada spec.
file.ffile.forfile.ftnfile.fiFixed form Fortran source code that should not be preprocessed.
file.Ffile.FORfile.fppfile.FPPfile.FTNFixed form Fortran source code that must be preprocessed (with the traditionalpreprocessor).
file.f90file.f95file.f03file.f08file.fiiFree form Fortran source code that should not be preprocessed.
file.F90file.F95file.F03file.F08Free form Fortran source code that must be preprocessed (with thetraditional preprocessor).
file.cobfile.COBfile.cblfile.CBLCOBOL source code.
file.goGo source code.
file.dD source code.
file.diD interface file.
file.ddD documentation code (Ddoc).
file.adsAda source code file that contains a library unit declaration (adeclaration of a package, subprogram, or generic, or a genericinstantiation), or a library unit renaming declaration (a package,generic, or subprogram renaming declaration). Such files are alsocalledspecs.
file.adbAda source code file containing a library unit body (a subprogram orpackage body). Such files are also calledbodies.
file.sAssembler code.
file.Sfile.sxAssembler code that must be preprocessed.
otherAn 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:
-xlanguage--language=language--languagelanguageSpecify explicitly thelanguage for the following input files(rather than letting the compiler choose a default based on the filename suffix). This option applies to all following input files untilthe next-x option. Possible values forlanguage are:
c c-header cpp-outputc++ c++-header c++-system-header c++-user-header c++-cpp-outputc++-system-moduleobjective-c objective-c-header objective-c-cpp-output objc-cpp-outputobjective-c++ objective-c++-header objective-c++-cpp-outputobjc++-cpp-outputassembler assembler-with-cppada adascil adawhycoboldf77 f77-cpp-input f95 f95-cpp-inputgomodula-2 modula-2-cpp-outputrustalgol68lto
Note that-x does not imply a particular language standard.For example-x f77 may also require-std=legacy for some oldersource codes.
-x noneTurn off any specification of a language, so that subsequent files arehandled according to their file name suffixes (as if-xhas not been used at all).
If you only want some of the stages of compilation, you can use-x (or filename suffixes) to tellgcc where to start, andone of the options-c,-S, or-E to say wheregcc is to stop. Note that some combinations (for example,‘-x cpp-output -E’) instructgcc to do nothing at all.
-c ¶--compileCompile or assemble the source files, but do not link. The linkingstage simply is not done. The ultimate output is in the form of anobject file for each source file.
By default, the object file name for a source file is made by replacingthe suffix ‘.c’, ‘.i’, ‘.s’, etc., with ‘.o’.
Unrecognized input files, not requiring compilation or assembly, areignored.
-S ¶--assembleStop after the stage of compilation proper; do not assemble. The outputis in the form of an assembler code file for each non-assembler inputfile specified.
By default, the assembler file name for a source file is made byreplacing the suffix ‘.c’, ‘.i’, etc., with ‘.s’.
Input files that don’t require compilation are ignored.
-E ¶--preprocessStop after the preprocessing stage; do not run the compiler proper. Theoutput is in the form of preprocessed source code, which is sent to thestandard output.
Input files that don’t require preprocessing are ignored.
-ofile ¶--output=file--outputfilePlace the primary output in filefile. This applies to whateversort of output is being produced, whether it be an executable file, anobject file, an assembler file or preprocessed C code.
If-o is not specified, the default is to put an executablefile ina.out, the object file forsource.suffix insource.o, itsassembler file insource.s, a precompiled header file insource.suffix.gch, and all preprocessed C source onstandard output.
Though-o names only the primary output, it also affects thenaming of auxiliary and dump outputs. See the examples below. Unlessoverridden, both auxiliary outputs and dump outputs are placed in thesame directory as the primary output. In auxiliary outputs, the suffixof the input file is replaced with that of the auxiliary output filetype; in dump outputs, the suffix of the dump file is appended to theinput file suffix. In compilation commands, the base name of bothauxiliary and dump outputs is that of the primary output; in compile andlink commands, the primary output name, minus the executable suffix, iscombined with the input file name. If both share the same base name,disregarding the suffix, the result of the combination is that basename, otherwise, they are concatenated, separated by a dash.
gcc -c foo.c ...
will usefoo.o as the primary output, and place aux outputs anddumps next to it, e.g., aux filefoo.dwo for-gsplit-dwarf, and dump filefoo.c.???r.final for-fdump-rtl-final.
If a non-linker output file is explicitly specified, aux and dump filesby default take the same base name:
gcc -c foo.c -o dir/foobar.o ...
will name aux outputsdir/foobar.* and dump outputsdir/foobar.c.*.
A linker output will instead prefix aux and dump outputs:
gcc foo.c bar.c -o dir/foobar ...
will generally name aux outputsdir/foobar-foo.* anddir/foobar-bar.*, and dump outputsdir/foobar-foo.c.* anddir/foobar-bar.c.*.
The one exception to the above is when the executable shares the basename with the single input:
gcc foo.c -o dir/foo ...
in which case aux outputs are nameddir/foo.* and dump outputsnameddir/foo.c.*.
The location and the names of auxiliary and dump outputs can be adjustedby the options-dumpbase,-dumpbase-ext,-dumpdir,-save-temps=cwd, and-save-temps=obj.
-dumpbasedumpbase ¶--dumpbasedumpbaseThis option sets the base name for auxiliary and dump output files. Itdoes not affect the name of the primary output file. Intermediateoutputs, when preserved, are not regarded as primary outputs, but asauxiliary outputs:
gcc -save-temps -S foo.c
saves the (no longer) temporary preprocessed file infoo.i, andthen compiles to the (implied) output filefoo.s, whereas:
gcc -save-temps -dumpbase save-foo -c foo.c
preprocesses to insave-foo.i, compiles tosave-foo.s (nowan intermediate, thus auxiliary output), and then assembles to the(implied) output filefoo.o.
Absent this option, dump and aux files take their names from the inputfile, or from the (non-linker) output file, if one is explicitlyspecified: dump output files (e.g. those requested by-fdump-*options) with the input name suffix, and aux output files (thoserequested by other non-dump options, e.g.-save-temps,-gsplit-dwarf,-fcallgraph-info) without it.
Similar suffix differentiation of dump and aux outputs can be attainedfor explicitly-given-dumpbase basename.suf by also specifying-dumpbase-ext .suf.
Ifdumpbase is explicitly specified with any directory component,anydumppfx specification (e.g.-dumpdir or-save-temps=*) is ignored, and instead of appending to it,dumpbase fully overrides it:
gcc foo.c -c -o dir/foo.o -dumpbase alt/foo \ -dumpdir pfx- -save-temps=cwd ...
creates auxiliary and dump outputs namedalt/foo.*, disregardingdir/ in-o, the./ prefix implied by-save-temps=cwd, andpfx- in-dumpdir.
When-dumpbase is specified in a command that compiles multipleinputs, or that compiles and then links, it may be combined withdumppfx, as specified under-dumpdir. Then, each inputfile is compiled using the combineddumppfx, and default valuesfordumpbase andauxdropsuf are computed for each inputfile:
gcc foo.c bar.c -c -dumpbase main ...
createsfoo.o andbar.o as primary outputs, and avoidsoverwriting the auxiliary and dump outputs by using thedumpbaseas a prefix, creating auxiliary and dump outputs namedmain-foo.*andmain-bar.*.
An empty string specified asdumpbase avoids the influence of theoutput basename in the naming of auxiliary and dump outputs duringcompilation, computing default values :
gcc -c foo.c -o dir/foobar.o -dumpbase '' ...
will name aux outputsdir/foo.* and dump outputsdir/foo.c.*. Note how their basenames are taken from the inputname, but the directory still defaults to that of the output.
The empty-string dumpbase does not prevent the use of the outputbasename for outputs during linking:
gcc foo.c bar.c -o dir/foobar -dumpbase '' -flto ...
The compilation of the source files will name auxiliary outputsdir/foo.* anddir/bar.*, and dump outputsdir/foo.c.* anddir/bar.c.*. LTO recompilation duringlinking will usedir/foobar. as the prefix for dumps andauxiliary files.
-dumpbase-extauxdropsuf ¶--dumpbase-extauxdropsufWhen forming the name of an auxiliary (but not a dump) output file, droptrailingauxdropsuf fromdumpbase before appending anysuffixes. If not specified, this option defaults to the suffix of adefaultdumpbase, i.e., the suffix of the input file when-dumpbase is not present in the command line, ordumpbaseis combined withdumppfx.
gcc foo.c -c -o dir/foo.o -dumpbase x-foo.c -dumpbase-ext .c ...
createsdir/foo.o as the main output, and generates auxiliaryoutputs indir/x-foo.*, taking the location of the primaryoutput, and dropping the.c suffix from thedumpbase. Dumpoutputs retain the suffix:dir/x-foo.c.*.
This option is disregarded if it does not match the suffix of aspecifieddumpbase, except as an alternative to the executablesuffix when appending the linker output base name todumppfx, asspecified below:
gcc foo.c bar.c -o main.out -dumpbase-ext .out ...
createsmain.out as the primary output, and avoids overwritingthe auxiliary and dump outputs by using the executable name minusauxdropsuf as a prefix, creating auxiliary outputs namedmain-foo.* andmain-bar.* and dump outputs namedmain-foo.c.* andmain-bar.c.*.
-dumpdirdumppfx ¶--dumpdirdumppfxWhen forming the name of an auxiliary or dump output file, usedumppfx as a prefix:
gcc -dumpdir pfx- -c foo.c ...
createsfoo.o as the primary output, and auxiliary outputs namedpfx-foo.*, combining the givendumppfx with the defaultdumpbase derived from the default primary output, derived in turnfrom the input name. Dump outputs also take the input name suffix:pfx-foo.c.*.
Ifdumppfx is to be used as a directory name, it must end with adirectory separator:
gcc -dumpdir dir/ -c foo.c -o obj/bar.o ...
createsobj/bar.o as the primary output, and auxiliary outputsnameddir/bar.*, combining the givendumppfx with thedefaultdumpbase derived from the primary output name. Dumpoutputs also take the input name suffix:dir/bar.c.*.
It defaults to the location of the output file, unless the outputfile is a special file like/dev/null. Options-save-temps=cwd and-save-temps=obj override thisdefault, just like an explicit-dumpdir option. In casemultiple such options are given, the last one prevails:
gcc -dumpdir pfx- -c foo.c -save-temps=obj ...
outputsfoo.o, with auxiliary outputs namedfoo.* because-save-temps=* overrides thedumppfx given by the earlier-dumpdir option. It does not matter that=obj is thedefault for-save-temps, nor that the output directory isimplicitly the current directory. Dump outputs are namedfoo.c.*.
When compiling from multiple input files, if-dumpbase isspecified,dumpbase, minus aauxdropsuf suffix, and a dashare appended to (or override, if containing any directory components) anexplicit or defaulteddumppfx, so that each of the multiplecompilations gets differently-named aux and dump outputs.
gcc foo.c bar.c -c -dumpdir dir/pfx- -dumpbase main ...
outputs auxiliary dumps todir/pfx-main-foo.* anddir/pfx-main-bar.*, appendingdumpbase- todumppfx.Dump outputs retain the input file suffix:dir/pfx-main-foo.c.*anddir/pfx-main-bar.c.*, respectively. Contrast with thesingle-input compilation:
gcc foo.c -c -dumpdir dir/pfx- -dumpbase main ...
that, applying-dumpbase to a single source, does not computeand append a separatedumpbase per input file. Its auxiliary anddump outputs go indir/pfx-main.*.
When compiling and then linking from multiple input files, a defaultedor explicitly specifieddumppfx also undergoes thedumpbase-transformation above (e.g. the compilation offoo.c andbar.c above, but without-c). If neither-dumpdir nor-dumpbase are given, the linker outputbase name, minusauxdropsuf, if specified, or the executablesuffix otherwise, plus a dash is appended to the defaultdumppfxinstead. Note, however, that unlike earlier cases of linking:
gcc foo.c bar.c -dumpdir dir/pfx- -o main ...
does not append the output namemain todumppfx, because-dumpdir is explicitly specified. The goal is that theexplicitly-specifieddumppfx may contain the specified output nameas part of the prefix, if desired; only an explicitly-specified-dumpbase would be combined with it, in order to avoid simplydiscarding a meaningful option.
When compiling and then linking from a single input file, the linkeroutput base name will only be appended to the defaultdumppfx asabove if it does not share the base name with the single input filename. This has been covered in single-input linking cases above, butnot with an explicit-dumpdir that inhibits the combination,even if overridden by-save-temps=*:
gcc foo.c -dumpdir alt/pfx- -o dir/main.exe -save-temps=cwd ...
Auxiliary outputs are namedfoo.*, and dump outputsfoo.c.*, in the current working directory as ultimately requestedby-save-temps=cwd.
Summing it all up for an intuitive though slightly imprecise data flow:the primary output name is broken into a directory part and a basenamepart;dumppfx is set to the former, unless overridden by-dumpdir or-save-temps=*, anddumpbase is setto the latter, unless overriden by-dumpbase. If there aremultiple inputs or linking, thisdumpbase may be combined withdumppfx and taken from each input file. Auxiliary output namesfor each input are formed by combiningdumppfx,dumpbaseminus suffix, and the auxiliary output suffix; dump output names areonly different in that the suffix fromdumpbase is retained.
When it comes to auxiliary and dump outputs created during LTOrecompilation, a combination ofdumppfx anddumpbase, asgiven or as derived from the linker output name but not from inputs,even in cases in which this combination would not otherwise be used assuch, is passed down with a trailing period replacing the compiler-addeddash, if any, as a-dumpdir option tolto-wrapper;being involved in linking, this program does not normally get any-dumpbase and-dumpbase-ext, and it ignores them.
When running sub-compilers,lto-wrapper appends LTO stagenames to the receiveddumppfx, ensures it contains a directorycomponent so that it overrides any-dumpdir, and passes that as-dumpbase to sub-compilers.
-v ¶--verbosePrint (on standard error output) the commands executed to run the stagesof compilation. Also print the version number of the compiler driverprogram and of the preprocessor and the compiler proper.
-### ¶Like-v except the commands are not executed and argumentsare quoted unless they contain only alphanumeric characters or./-_.This is useful for shell scripts to capture the driver-generated command lines.
--help ¶Print (on the standard output) a description of the command-line optionsunderstood bygcc. If the-v option is also specifiedthen--help is also passed on to the various processesinvoked bygcc, so that they can display the command-line optionsthey accept. If the-Wextra option has also been specified(prior to the--help option), then command-line options thathave no documentation associated with them are also displayed.
--target-help ¶Print (on the standard output) a description of target-specific command-lineoptions for each tool. For some targets extra target-specificinformation may also be printed.
--help={class|[^]qualifier}[,…]Print (on the standard output) a description of the command-lineoptions understood by the compiler that fit into all specified classesand qualifiers. These are the supported classes:
Display all of the optimization options supported by thecompiler.
Display all of the options controlling warning messagesproduced by the compiler.
Display target-specific options. Unlike the--target-help option however, target-specific options of thelinker and assembler are not displayed. This is because thosetools do not currently support the extended--help= syntax.
Display the values recognized by the--paramoption.
Display the options supported forlanguage, wherelanguage is the name of one of the languages supported in thisversion of GCC. If an option is supported by all languages, one needsto select ‘common’ class.
Display the options that are common to all languages.
These are the supported qualifiers:
Display only those options that are undocumented.
Display options taking an argument that appears after an equalsign in the same continuous piece of text, such as:‘--help=target’.
Display options taking an argument that appears as a separate wordfollowing the original option, such as: ‘-o output-file’.
Thus for example to display all the undocumented target-specificswitches 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 warningoptions (i.e., ones that are either on or off and that do not take anargument) that have a description, use:
--help=warnings,^joined,^undocumented
The argument to--help= should not consist solely of invertedqualifiers.
Combining several classes is possible, although this usuallyrestricts the output so much that there is nothing to display. Onecase where it does work, however, is when one of the classes istarget. For example, to display all the target-specificoptimization options, use:
--help=target,optimizers
The--help= option can be repeated on the command line. Eachsuccessive use displays its requested class of options, skippingthose that have already been displayed. If--help is alsospecified anywhere on the command line then this takes precedenceover any--help= option.
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 displayedoptions, an indication is given as to whether the option is enabled,disabled or set to a specific value (assuming that the compilerknows this at the point where the--help= option is used).
Here is a truncated example from the ARM port ofgcc:
% 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-lineoptions, so for example it is possible to find out which optimizationsare enabled at-O2 by using:
-Q -O2 --help=optimizers
Alternatively you can discover which binary optimizations are enabledby-O3 by using:
gcc -c -Q -O3 --help=optimizers > /tmp/O3-optsgcc -c -Q -O2 --help=optimizers > /tmp/O2-optsdiff /tmp/O2-opts /tmp/O3-opts | grep enabled
--version ¶Display the version number and copyrights of the invoked GCC.
-pass-exit-codes ¶--pass-exit-codesNormally thegcc program exits with the code of 1 if anyphase of the compiler returns a non-success return code. If you specify-pass-exit-codes, thegcc program instead returns withthe numerically highest error produced by any phase returning an errorindication. The C, C++, and Fortran front ends return 4 if an internalcompiler error is encountered.
-pipe ¶--pipeUse pipes rather than temporary files for communication between thevarious stages of compilation. This fails to work on some systems wherethe assembler is unable to read from a pipe; but the GNU assembler hasno trouble.
-specs=file ¶--specs=file--specsfileProcessfile after the compiler reads in the standardspecsfile, in order to override the defaults which thegcc driverprogram uses when determining what switches to pass tocc1,cc1plus,as,ld, etc. More than one-specs=file can be specified on the command line, and theyare processed in order, from left to right. SeeSpecifying Subprocesses and the Switches to Pass to Them, forinformation about the format of thefile.
-wrapper ¶Invoke all subcommands under a wrapper program. The name of thewrapper program and its parameters are passed as a comma separatedlist.
gcc -c t.c -wrapper gdb,--args
This invokes all subprograms ofgcc under‘gdb --args’, thus the invocation ofcc1 is‘gdb --args cc1 …’.
-ffile-prefix-map=old=new ¶When compiling files residing in directoryold, recordany references to them in the result of the compilation as if thefiles resided in directorynew instead. Specifying thisoption is equivalent to specifying all the individual-f*-prefix-map options. This can be used to make reproduciblebuilds that are location independent. Directories referenced bydirectives are not affected by these options. See also-fmacro-prefix-map,-fdebug-prefix-map,-fprofile-prefix-map and-fcanon-prefix-map.
-fcanon-prefix-map ¶For the-f*-prefix-map options normally comparisonofold prefix against the filename that would be normallyreferenced in the result of the compilation is done using textualcomparison of the prefixes, or ignoring character case for case insensitivefilesystems and considering slashes and backslashes as equal on DOS basedfilesystems. The-fcanon-prefix-map causes such comparisonsto be done on canonicalized paths ofoldand the referenced filename.
-fplugin=name.so ¶Load the plugin code in filename.so, assumed to be ashared object to be dlopen’d by the compiler. The base name ofthe shared object file is used to identify the plugin for thepurposes of argument parsing (See-fplugin-arg-name-key=value below).Each plugin should define the callback functions specified in thePlugins API.
-fplugin-arg-name-key=value ¶Define an argument calledkey with a value ofvaluefor the plugin calledname.
-fdump-ada-spec[-slim] ¶For C and C++ source and include files, generate corresponding Ada specs.SeeGenerating Ada Bindings for C and C++ headers inGNAT User’s Guide, which provides detailed documentation on this feature.
-fada-spec-parent=unit ¶In conjunction with-fdump-ada-spec[-slim] above, generateAda specs as child units of parentunit.
-fdump-go-spec=file ¶For input files in any language, generate corresponding Godeclarations infile. This generates Goconst,type,var, andfunc declarations which may be auseful way to start writing a Go interface to code written in someother language.
@fileRead command-line options fromfile. The options read areinserted in place of the original @file option. Iffiledoes not exist, or cannot be read, then the option will be treatedliterally, and not removed.
Options infile are separated by whitespace. A whitespacecharacter may be included in an option by surrounding the entireoption in either single or double quotes. Any character (including abackslash) may be included by prefixing the character to be includedwith a backslash. Thefile may itself contain additional@file options; any such options will be processed recursively.
Next:Compiling C++ Programs, Previous:Option Summary, Up:GCC Command Options [Contents][Index]