你会相信吗?我在看GCC 文档
我自己都有点不相信。
gcc 4阶段
预处理 preprocessing
编译 compilation
汇编 assembly
链接 linking
GCC 能将几个文件预处理、编译成一个或几个汇编文件(assembly file)
->每个汇编文件产生一个目标文件(object file)
->链接所有的目标文件 形成一个可执行文件(executable file)
Overall Options
-c -S -E -o file -no-canonical-prefixes
-pipe -pass-exit-codes
-x language -v -### --help[=class[,...]] --target-help
--version -wrapper @file -fplugin=file -fplugin-arg-name=arg
-fdump-ada-spec[-slim] -fada-spec-parent=arg -fdump-go-spec=file
C Language Options
-ansi -std=standard -fgnu89-inline
-aux-info filename -fallow-parameterless-variadic-functions
-fno-asm -fno-builtin -fno-builtin-function
-fhosted -ffreestanding -fopenmp -fms-extensions -fplan9-extensions
-trigraphs -traditional -traditional-cpp
-fallow-single-precision -fcond-mismatch -flax-vector-conversions
-fsigned-bitfields -fsigned-char
-funsigned-bitfields -funsigned-char
C++ Language Options
-fabi-version=n -fno-access-control -fcheck-new
-fconstexpr-depth=n -ffriend-injection
-fno-elide-constructors
-fno-enforce-eh-specs
-ffor-scope -fno-for-scope -fno-gnu-keywords
-fno-implicit-templates
-fno-implicit-inline-templates
-fno-implement-inlines -fms-extensions
-fno-nonansi-builtins -fnothrow-opt -fno-operator-names
-fno-optional-diags -fpermissive
-fno-pretty-templates
-frepo -fno-rtti -fstats -ftemplate-backtrace-limit=n
-ftemplate-depth=n
-fno-threadsafe-statics -fuse-cxa-atexit -fno-weak -nostdinc++
-fno-default-inline -fvisibility-inlines-hidden
-fvisibility-ms-compat
-fext-numeric-literals
-Wabi -Wconversion-null -Wctor-dtor-privacy
-Wdelete-non-virtual-dtor -Wliteral-suffix -Wnarrowing
-Wnoexcept -Wnon-virtual-dtor -Wreorder
-Weffc++ -Wstrict-null-sentinel
-Wno-non-template-friend -Wold-style-cast
-Woverloaded-virtual -Wno-pmf-conversions
-Wsign-promo
Options Controlling the Kind of Output 选择控制的输出
file.c C source code that must be preprocessed.
必须预处理的C源代码
file.i C source code that should not be preprocessed.
不应该预处理的C源代码
file.ii C++ source code that should not be preprocessed.
不应该预处理的C++源代码
file.h C, C++, Objective-C or Objective-C++ header file to be turned into a
precompiled header (default), or C, C++ header file to be turned into an Ada spec (via
the ‘-fdump-ada-spec’ switch).
..头文件被转换成一个默认的预编译头文件
file.C .cp .cxx .cpp .CPP .c++ .cc .mm .M C++ source code that must be preprocessed.
必须被编译的C++ 文件
输入
-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:
明确指定以下的语言输入文件(而不是让编译器选择一个默认的基于文件名后缀)。这个选项适用于下面的所有的输入
文件,直到下一个-x选项
c c-header cpp-output c++ c++-header c++-cpp-output objective-c objective-c-header objective-c-cpp-output objective-c++ objective-c++-header objective-c++-cpp- output assembler assembler-with-cpp ada f77 f77-cpp-input f95 f95-cpp-input go java
-x none
Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they areif ‘-x’ has not been used at all).
关掉所有的语言规范,以便后续文件根据文件名后缀处理文件
-pass-exit-codes
Normally the gcc program exits with the code of 1 if any phase of the compiler returns a non-success return code. If you specify ‘-pass-exit-codes’, the gcc program instead returns with the numerically highest error produced by any phase returning an error indication. The C, C++, and Fortran front ends return 4 if an internal compiler error is encountered.
这段话是什么意思。有道没翻译出来
输出
-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 that don’t require preprocessing are ignored.
预处理后停止 不进行编译
-o file
Place output in file file. This applies to whatever sort of output is being pro-duced, whether it be an executable file, an object file, an ssembler file or preprocessed C code.
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 rce.s’, a precompiled header file in ‘source.suffix.gch’, 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.
打印编译阶段的错误 处理器版本号 编译器驱动程序
-###
Like ‘-v’ except the commands are not executed and arguments are quoted unless they contain only alphanumeric characters or ./-_. This is useful for shell scripts to capture the driver-generated command lines.
-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.
编译的时候使用管道而不是临时文件
--help
Print (on the standard output) a description of the command-line options under-stood by gcc. If the ‘-v’ option is also specified then ‘--help’ is also passed on to the various processes invoked by gcc, so that they can display the command-line options they accept. If the ‘-Wextra’ option has also been specified (prior to the ‘--help’ option), then command-line options that have no documentation associated with them are also displayed.
--version
Display the version number and copyrights of the invoked GCC.
版本
-wrapper
Invoke all subcommands under a wrapper program. The name of the wrapper program and its parameters are passed as a comma separated list.
gcc -c t.c -wrapper gdb,--args
This invokes all subprograms of gcc under ‘gdb --args’, thus the invocation of cc1 is ‘gdb --args cc1 ...’.
包装器 (解释:包装器调用所有的子程序。包装程序的名称和它的参数通过逗号隔开,例子,gdb --args调用所有的子程序 因此cc1调用gdb --args cc1 ..)
-fplugin=name.so
Load the plugin code in file name.so, assumed to be a shared object to be dlopen’d by the compiler. The base name of the shared object file is used to identify the plugin for the purposesof argument parsing (See ‘-fplugin-arg-name-key=value’ below). Each plugin should define the callback functions specified in the Plugins API.
加载name.so插件
-fdump-ada-spec[-slim]
For C and C++ source and include files, generate corresponding Ada specs. See Section “Generating Ada Bindings for C and C++ headers” in GNAT User’s Guide, which provides detailed documentation on this feature.
对于C和c++源码,包括文件,生成相应的ada specs
-fdump-go-spec=file
For input files in any language, generate corresponding Go declarations in file. This generates Go const, type, var, and func declarations which may be a useful way to start writing a Go interface to code written in some other language.
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively.
从文件读取命令行选项
Options Controlling C Dialect C方言控制选项
-ansi
In C mode, this is equivalent to ‘-std=c90’. In C++ mode, it is equivalent to ‘-std=c++98’.
The alternate keywords __asm__, __extension__, __inline__ and __typeof__ continue to work despite ‘-ansi’. You would not want to use them in an ISO 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-ISO programs to be rejected gratuitously. For that, ‘-Wpedantic’ is required in addition to ‘-ansi’. See Section 3.8 [Warning Options], page 50.
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 ISO standard doesn’t call for; this is to avoid interfering with any programs that might use these names for other things.
Functions that are normally built in but do not have semantics defined by ISO C (such as alloca and ffs) are not built-in functions when ‘-ansi’ is used. See Section 6.55 [Other built-in functions provided by GCC], page 451, for details of the functions affected.
在C模式下相当于-std=c90 c++模式下相当于-std=c++98
-std=
Determine the language standard. See Chapter 2 [Language Standards Sup-ported by GCC], page 5, for details of these standard versions. This option is currently only supported when compiling C or C++.
The compiler can accept several base standards, such as ‘c90’ or ‘c++98’, and GNU dialects of those standards, such as ‘gnu90’ or ‘gnu++98’. When a base standard is specified, the compiler accepts all programs following that stan-dard plus those using GNU extensions that do not contradict it. For example,‘-std=c90’ turns off certain features of GCC that are incompatible with ISO C90, such as the asm and typeof keywords, but not other GNU extensions that do not have a meaning in ISO C90, such as omitting the middle term of a ?: expression. On the other hand, when a GNU dialect of a standard is specified, all features supported by the compiler are enabled, even when those features change the meaning of the base standard. As a result, some strict-conforming programs may be rejected. The particular standard is used by ‘-Wpedantic’ to identify which features are GNU extensions given that version of the standard. For example ‘-std=gnu90 -Wpedantic’ warns about C++ style ‘//’ comments, while ‘-std=gnu99 -Wpedantic’ does not.
A value for this option must be provided; possible values are
‘c90’
‘c89’
‘iso9899:1990’
Support all ISO C90 programs (certain GNU extensions that con-flict with ISO C90 are disabled). Same as ‘-ansi’ for C code.
‘iso9899:199409’
ISO C90 as modified in amendment 1.
‘c99’
‘c9x’
‘iso9899:1999’
‘iso9899:199x’
ISO C99. Note that this standard is not yet fully supported; see http://gcc.gnu.org/c99status.html for more information. The names ‘c9x’ and ‘iso9899:199x’ are deprecated.
‘c11’
‘c1x’
‘iso9899:2011’
ISO C11, the 2011 revision of the ISO C standard. Support is incomplete and experimental. The name ‘c1x’ is deprecated.
‘gnu90’
‘gnu89’
GNU dialect of ISO C90 (including some C99 features). This is the default for C code.
‘gnu99’
‘gnu9x’
GNU dialect of ISO C99. When ISO C99 is fully implemented in GCC, this will become the default. The name ‘gnu9x’ is deprecated.
‘gnu11’
‘gnu1x’
GNU dialect of ISO C11. Support is incomplete and experimental.The name ‘gnu1x’ is deprecated.
‘c++98’
‘c++03’
The 1998 ISO C++ standard plus the 2003 technical corrigendum and some additional defect reports. Same as ‘-ansi’ for C++ code.
gnu++98’
‘gnu++03’
GNU dialect of ‘-std=c++98’. This is the default for C++ code.
‘c++11’
‘c++0x’
The 2011 ISO C++ standard plus amendments. Support for C++11 is still experimental, and may change in incompatible ways in future releases. The name ‘c++0x’ is deprecated.
‘gnu++11’
‘gnu++0x’
GNU dialect of ‘-std=c++11’. Support for C++11 is still experi-mental, and may change in incompatible ways in future releases.The name ‘gnu++0x’ is deprecated.
‘c++1y’
The next revision of the ISO C++ standard, tentatively planned for 2017. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.
‘gnu++1y’
GNU dialect of ‘-std=c++1y’. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.
确定语言标准
-fgnu89-inline
The option ‘-fgnu89-inline’ tells GCC to use the traditional GNU semantics for inline functions when in C99 mode.
在c99模式下内联函数使用传统的GUN工作流程
-aux-info filename
Output to the given filename prototyped declarations for all functions declared and/or defined in a translation unit, including those in header files. This option is silently ignored in any language other than C.
-fallow-parameterless-variadic-functions
Accept variadic functions without named parameters.
-fno-asm
Do not recognize 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, which has the same effect. In C99 mode (‘-std=c99’ or ‘-std=gnu99’), this switch only affects the asm and typeof keywords, since inline is a standard keyword in ISO C99.
不识别asm, inline or typeof 作为关键字 所以代码可以使用这些字作为标识符
-fno-builtin
-fno-builtin-function
Don’t recognize built-in functions that do not begin with ‘__builtin_’ as prefix.See Section 6.55 [Other built-in functions provided by GCC], page 451, for details of the functions affected, including those which are not built-in functions when ‘-ansi’ or ‘-std’ options for strict ISO C onformance are used because they do not have an ISO standard meaning
-fhosted
Assert that compilation targets 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 targets 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’.
-fopenmp
Enable handling of OpenMP directives #pragma omp in C/C++ and !$omp in Fortran. When ‘-fopenmp’ is specified, the compiler generates parallel code according to the OpenMP Application Program Interface v3.0 http://www.openmp.org/. This option implies ‘-pthread’, and thus is only supported on targets that have support for ‘-pthread’.
-fgnu-tm
When the option ‘-fgnu-tm’ is specified, the compiler generates code for the Linux variant of Intel’s current Transactional Memory ABI specification doc-ument (Revision 1.1, May 6 2009). This is an experimental feature whose interface may change in future versions of GCC, as the official specification changes. Please note that not all architectures are supported for this feature. For more information on GCC’s support for transactional memory, See Section “The GNU Transactional Memory Library” in GNU Transactional Memory Library.
-fms-extensions
Accept some non-standard constructs used in Microsoft header files.
In C++ code, this allows member names in structures to be similar to previous types declarations.
typedef int UOW;
struct ABC {
UOW UOW;
};
Some cases of unnamed fields in structures and unions are only accepted with this option. See Section 6.59 [Unnamed struct/union fields within structs/unions], page 641, for details.
-fplan9-extensions
Accept some non-standard constructs used in Plan 9 code. This enables ‘-fms-extensions’, permits passing pointers to structures with anonymous fields to functions that expect pointers to elements of the type of the field, and permits referring to anonymous fields declared using a typedef. See Section 6.59 [Unnamed struct/union fields within structs/unions], page 641, for details. This is only supported for C, not C++.
-trigraphs
Support ISO C trigraphs. The ‘-ansi’ option (and ‘-std’ options for strict ISO C conformance) implies ‘-trigraphs’.
-traditional
-traditional-cpp
Formerly, these options caused GCC to attempt to emulate a pre-standard C compiler. They are now only supported with the ‘-E’ switch. The preprocessor continues to support a pre-standard mode. See the GNU CPP manual for details.
-fcond-mismatch
Allow conditional expressions with mismatched types in the second and third arguments. The value of such an expression is void. This option is not supported for C++.
-flax-vector-conversions Allow implicit conversions between vectors with differing numbers of elements and/or incompatible element types. This option should not be used for new code.
-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 equiv-alent to ‘-funsigned-char’.
-fsigned-bitfields
-funsigned-bitfields
-fno-signed-bitfields
-fno-unsigned-bitfields
These options control whether a bit-field is signed or unsigned, when the dec-laration does not use either signed or unsigned. By default, such a bit-field is signed, because this is consistent: the basic integer types such as int are signed types.
突然发现好多都用不上。。。。。先弄这些吧