📄 invoke.texi
字号:
* Optimize Options:: How much optimization?* Preprocessor Options:: Controlling header files and macro definitions. Also, getting dependency information for Make.* Assembler Options:: Passing options to the assembler.* Link Options:: Specifying libraries and so on.* Directory Options:: Where to find header files and libraries. Where to find the compiler executable files.* Target Options:: Running a cross-compiler, or an old version of GNU CC.@end menu@node Overall Options@section Options Controlling the Kind of OutputCompilation can involve up to four stages: preprocessing, compilationproper, assembly and linking, always in that order. The first threestages apply to an individual source file, and end by producing anobject file; linking combines all the object files (those newlycompiled, and those specified as input) into an executable file.@cindex file name suffixFor any given input file, the file name suffix determines what kind ofcompilation is done:@table @code@item @var{file}.cC source code which must be preprocessed.@item @var{file}.iC source code which should not be preprocessed.@item @var{file}.iiC++ source code which should not be preprocessed.@item @var{file}.mObjective-C source code. Note that you must link with the library@file{libobjc.a} to make an Objective-C program work.@item @var{file}.hC header file (not to be compiled or linked).@item @var{file}.cc@itemx @var{file}.cxx@itemx @var{file}.cpp@itemx @var{file}.CC++ source code which must be preprocessed. Note that in @samp{.cxx},the last two letters must both be literally @samp{x}. Likewise,@samp{.C} refers to a literal capital C.@item @var{file}.s Assembler code.@item @var{file}.SAssembler code which must be preprocessed.@item @var{other}An object file to be fed straight into linking.Any file name with no recognized suffix is treated this way.@end tableYou can specify the input language explicitly with the @samp{-x} option:@table @code@item -x @var{language}Specify explicitly the @var{language} 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 @samp{-x} option. Possible values for @var{language} are:@examplec objective-c c++c-header cpp-output c++-cpp-outputassembler assembler-with-cpp@end example@item -x noneTurn off any specification of a language, so that subsequent files arehandled according to their file name suffixes (as they are if @samp{-x}has not been used at all).@end tableIf you only want some of the stages of compilation, you can use@samp{-x} (or filename suffixes) to tell @code{gcc} where to start, andone of the options @samp{-c}, @samp{-S}, or @samp{-E} to say where@code{gcc} is to stop. Note that some combinations (for example,@samp{-x cpp-output -E} instruct @code{gcc} to do nothing at all.@table @code@item -cCompile 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 @samp{.c}, @samp{.i}, @samp{.s}, etc., with @samp{.o}.Unrecognized input files, not requiring compilation or assembly, areignored.@item -SStop 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 @samp{.c}, @samp{.i}, etc., with @samp{.s}.Input files that don't require compilation are ignored.@item -EStop 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 which don't require preprocessing are ignored.@cindex output file option@item -o @var{file}Place output in file @var{file}. This applies regardless to whateversort 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 touse @samp{-o} when compiling more than one input file, unless you areproducing an executable file as output.If @samp{-o} is not specified, the default is to put an executable filein @file{a.out}, the object file for @file{@var{source}.@var{suffix}} in@file{@var{source}.o}, its assembler file in @file{@var{source}.s}, andall preprocessed C source on standard output.@refill@item -vPrint (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.@item -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.@end table@node Invoking G++@section Compiling C++ Programs@cindex suffixes for C++ source@cindex C++ source file suffixesC++ source files conventionally use one of the suffixes @samp{.C},@samp{.cc}, @samp{cpp}, or @samp{.cxx}; preprocessed C++ files use thesuffix @samp{.ii}. GNU CC recognizes files with these names andcompiles them as C++ programs even if you call the compiler the same wayas for compiling C programs (usually with the name @code{gcc}).@findex g++@findex c++However, C++ programs often require class libraries as well as acompiler that understands the C++ language---and under somecircumstances, you might want to compile programs from standard input,or otherwise without a suffix that flags them as C++ programs.@code{g++} is a program that calls GNU CC with the default languageset to C++, and automatically specifies linking against the GNU classlibrary libg++.@cindex @code{g++ 1.@var{xx}}@cindex @code{g++}, separate compiler@cindex @code{g++} older version@footnote{Prior to release 2 of the compiler,there was a separate @code{g++} compiler. That version was based on GNUCC, but not integrated with it. Versions of @code{g++} with a@samp{1.@var{xx}} version number---for example, @code{g++} version 1.37or 1.42---are much less reliable than the versions integrated with GCC2. Moreover, combining G++ @samp{1.@var{xx}} with a version 2 GCC willsimply not work.} On many systems, the script @code{g++} is alsoinstalled with the name @code{c++}.@cindex invoking @code{g++}When you compile C++ programs, you may specify many of the samecommand-line options that you use for compiling programs in anylanguage; or command-line options meaningful for C and relatedlanguages; or options that are meaningful only for C++ programs.@xref{C Dialect Options,,Options Controlling C Dialect}, forexplanations of options for languages related to C.@xref{C++ Dialect Options,,Options Controlling C++ Dialect}, forexplanations of options that are meaningful only for C++ programs.@node C Dialect Options@section Options Controlling C Dialect@cindex dialect options@cindex language dialect options@cindex options, dialectThe following options control the dialect of C (or languages derivedfrom C, such as C++ and Objective C) that the compiler accepts:@table @code@cindex ANSI support@item -ansiSupport all ANSI standard C programs.This turns off certain features of GNU C that are incompatible with ANSIC, such as the @code{asm}, @code{inline} and @code{typeof} keywords, andpredefined macros such as @code{unix} and @code{vax} that identify thetype of system you are using. It also enables the undesirable andrarely used ANSI trigraph feature, disallows @samp{$} as part ofidentifiers, and disables recognition of C++ style @samp{//} comments.The alternate keywords @code{__asm__}, @code{__extension__},@code{__inline__} and @code{__typeof__} continue to work despite@samp{-ansi}. You would not want to use them in an ANSI C program, ofcourse, but it is useful to put them in header files that might be includedin compilations done with @samp{-ansi}. Alternate predefined macrossuch as @code{__unix__} and @code{__vax__} are also available, with orwithout @samp{-ansi}.The @samp{-ansi} option does not cause non-ANSI programs to berejected gratuitously. For that, @samp{-pedantic} is required inaddition to @samp{-ansi}. @xref{Warning Options}.The macro @code{__STRICT_ANSI__} is predefined when the @samp{-ansi}option is used. Some header files may notice this macro and refrainfrom declaring certain functions or defining certain macros that theANSI standard doesn't call for; this is to avoid interfering with anyprograms that might use these names for other things.The functions @code{alloca}, @code{abort}, @code{exit}, and@code{_exit} are not builtin functions when @samp{-ansi} is used.@item -fno-asmDo not recognize @code{asm}, @code{inline} or @code{typeof} as akeyword, so that code can use these words as identifiers. You can usethe keywords @code{__asm__}, @code{__inline__} and @code{__typeof__}instead. @samp{-ansi} implies @samp{-fno-asm}.In C++, this switch only affects the @code{typeof} keyword, since@code{asm} and @code{inline} are standard keywords. You may want touse the @samp{-fno-gnu-keywords} flag instead, as it also disables theother, C++-specific, extension keywords such as @code{headof}.@item -fno-builtin@cindex builtin functions@findex abort@findex abs@findex alloca@findex cos@findex exit@findex fabs@findex ffs@findex labs@findex memcmp@findex memcpy@findex sin@findex sqrt@findex strcmp@findex strcpy@findex strlenDon't recognize builtin functions that do not begin with two leadingunderscores. Currently, the functions affected include @code{abort},@code{abs}, @code{alloca}, @code{cos}, @code{exit}, @code{fabs},@code{ffs}, @code{labs}, @code{memcmp}, @code{memcpy}, @code{sin},@code{sqrt}, @code{strcmp}, @code{strcpy}, and @code{strlen}.GCC normally generates special code to handle certain builtin functionsmore efficiently; for instance, calls to @code{alloca} may become singleinstructions that adjust the stack directly, and calls to @code{memcpy}may become inline copy loops. The resulting code is often both smallerand faster, but since the function calls no longer appear as such, youcannot set a breakpoint on those calls, nor can you change the behaviorof the functions by linking with a different library.The @samp{-ansi} option prevents @code{alloca} and @code{ffs} from beingbuiltin functions, since these functions do not have an ANSI standardmeaning.@item -trigraphsSupport ANSI C trigraphs. You don't want to know about thisbrain-damage. The @samp{-ansi} option implies @samp{-trigraphs}.@cindex traditional C language@cindex C language, traditional@item -traditionalAttempt to support some aspects of traditional C compilers.Specifically:@itemize @bullet@itemAll @code{extern} declarations take effect globally even if theyare written inside of a function definition. This includes implicitdeclarations of functions.@itemThe newer keywords @code{typeof}, @code{inline}, @code{signed}, @code{const}and @code{volatile} are not recognized. (You can still use thealternative keywords such as @code{__typeof__}, @code{__inline__}, andso on.)@itemComparisons between pointers and integers are always allowed.@itemInteger types @code{unsigned short} and @code{unsigned char} promoteto @code{unsigned int}.@itemOut-of-range floating point literals are not an error.@itemCertain constructs which ANSI regards as a single invalid preprocessingnumber, such as @samp{0xe-0xd}, are treated as expressions instead.@itemString ``constants'' are not necessarily constant; they are stored inwritable space, and identical looking constants are allocatedseparately. (This is the same as the effect of@samp{-fwritable-strings}.)@cindex @code{longjmp} and automatic variables@itemAll automatic variables not declared @code{register} are preserved by@code{longjmp}. Ordinarily, GNU C follows ANSI C: automatic variablesnot declared @code{volatile} may be clobbered.@item@kindex \x@kindex \a@cindex escape sequences, traditionalThe character escape sequences @samp{\x} and @samp{\a} evaluate as theliteral characters @samp{x} and @samp{a} respectively. Without@w{@samp{-traditional}}, @samp{\x} is a prefix for the hexadecimalrepresentation of a character, and @samp{\a} produces a bell.@itemIn C++ programs, assignment to @code{this} is permitted with@samp{-traditional}. (The option @samp{-fthis-is-variable} also hasthis effect.)@end itemizeYou may wish to use @samp{-fno-builtin} as well as @samp{-traditional}if your program uses names that are normally GNU C builtin functions forother purposes of its own.You cannot use @samp{-traditional} if you include any header files thatrely on ANSI C features. Some vendors are starting to ship systems withANSI C header files and you cannot use @samp{-traditional} on suchsystems to compile files that include any system headers.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -