翻译这篇文章时明显感觉到难度加大,个别句子暂时无法理解,已用大号字体标出,希望以后能够补上
Using the GNU Compiler Collection
3 GCC Command Options
3.2 Options Controlling the Kind of Output
控制输出种类的选项
Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order.
编译可以包括多达4个阶段:按顺序 预处理,编译本身,装配(汇编)和链接
GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file;
GCC 能够将几个文件通过预处理和编译生成一个或多个汇编输入文件
then each assembler input file produces an object file,
然后每个汇编器输入文件都会生成一个目标文件
and linking combines all the object files (those newly compiled, and those specified as input) into an executable file.
并且所有目标文件将链接(新编译的文件和指定为输入的文件)组合到一个可执行文件中。
For any given input file, the fle name suffix determines what kind of compilation is done:
对于任何给定的输入文件,文件名后缀决定了完成编译的方式:
后缀名 | |
---|---|
file.c | C source code that must be preprocessed. |
file.i | C source code that should not be preprocessed. |
file.ii | C++ source code that should not be preprocessed. |
file.m | Objective-C source code. Note that you must link with the ‘libobjc’ library to make an Objective-C program work. |
file.mi | Objective-C source code that should not be preprocessed. |
file.mm file.M | Objective-C++ source code. Note that you must link with the ‘libobjc’ library to make an Objective-C++ program work. Note that ‘.M’ refers to a literal capital M. Objective-C++ source code that must be preprocessed. |
file.mii | Objective-C++ source code that should not be preprocessed. |
file.h | C, C++, Objective-C or Objective-C++ header fle to be turned into a precompiled header (default), or C, C++ header fle to be turned into an Ada spec (via the ‘-fdump-ada-spec’ switch). |
file.cc file.cp file.cxx file.cpp file.CPP file.c++ file.C | C++ 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.hh file.H file.hp file.hxx file.hpp file.HPP file.h++ file.tc | C++ header fle to be turned into a precompiled header or Ada spec. |
file.f file.for file.ftn | Fixed form Fortran source code that should not be preprocessed. |
file.F file.FOR file.fpp file.FPP file.FTN | Fixed form Fortran source code that must be preprocessed (with the traditional preprocessor). |
file.f90 file.f95 file.f03 file.f08 | Free form Fortran source code that must be preprocessed (with the traditional preprocessor). |
file.go | Go source code. |
file.brig | BRIG files (binary representation of HSAIL). |
file.ads | Ada source code fle that contains a library unit declaration (a declaration of a package, subprogram, or generic, or a generic instantiation), or a library unit renaming declaration (a package, generic, or subprogram renaming declaration). Such fles are also called specs. |
file.adb | Ada source code fle containing a library unit body (a subprogram or package body). Such fles are also called bodies. |
file.s file.S file.sx | Assembler code that must be preprocessed. |
other | Any fle name with no recognized suffix is treated this way. |
You can specify the input language explicitly with the ‘-x’ option:
您可以使用 ‘-x’ 选项明确指定输入语言:
-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.
此选项适用于所有以下输入文件,直到下一个“-x”选项。
Possible values for language are:
language 可取值为:
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
brig
-x none
Turn off any specifcation 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).
关闭语言规范,以便后续文件根据文件名后缀进行处理(如果没有再次使用’-x’)。
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.
如果只需要编译某些阶段,可以使用’-x’(或文件名后缀)来告诉gcc从哪里开始,在加上一个选项’-c’,’-S’ 或 ‘-E’ 来说明gcc要停止的位置。
Note that some combinations (for example, ‘-x cpp-output -E’) instruct gcc to do nothing at all.
请注意,某些组合指令(如,’-x cpp-output -E’) gcc 完全不执行任何操作。
-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’.
默认情况下,源文件的目标文件名后缀用’.o’ 来替换 ‘.c’,’.i’,’.s’等。
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’.
默认情况下,源文件的汇编文件名后缀用 ‘.s’ 来替换 ‘.c’, ‘.i’ 等
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.
将输出放在文件 file 中
This applies to whatever sort of output is being produced,
whether it be an executable file, an object file, an assembler file or preprocessed C code.
这适用于正在生产的任何类型的输出,无论是可执行文件,目标文件,汇编程序文件还是预处理的C代码。
If ‘-o’ is not specifed, the default is to put an executable file in ‘a.out’, the object file for ‘source.suffix’ in ‘source.o’,
如果没有指定’-o’,那么默认情况是都放在可执行文件’a.out’中, ‘source.o’中的’source.suffix’对象文件
its assembler file in ‘source.s’, a precompiled header file in ‘source.suffix.gch’, and all preprocessed C source on standard output.
‘source.s’中的汇编文件,’source.suffix.gch’中的预编译头文件,以及标准输出上的所有预处理C源。
-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 ./-_.
可以理解为同 -v 选项一样,但更适合 shell 脚本使用
This is useful for shell scripts to capture the driver-generated command lines.
这对于shell脚本来捕获驱动程序生成的命令行非常有用。
--help
Print (on the standard output) a description of the command-line options understood by gcc.
打印(在标准输出上)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 commandline options they accept.
如果还指定了 ‘-v’ 选项,’–help’ 也会被传递给gcc调用的各种进程,以便他们可以显示他们能接受的命令行选项。
If the ‘-Wextra’ option has also been specifed (prior to the ‘–help’ option),
then command-line options that have no documentation associated with them are also displayed.
如果还指定了 ‘-Wextra’ 选项(在’–help’选项之前),那么没有文档关联的命令行选项也会显示。
--target-help
Print (on the standard output) a description of target-specifc command-line options for each tool.
打印(在标准输出上)每个工具的指定的命令行选项的描述。
For some targets extra target-specifc information may also be printed.
对于某些目标选项,还可以打印额外信息。
--help={class|[^]qualifier}[,...]
Print (on the standard output) a description of the command-line options understood by the compiler that fit into all specified classes and qualifiers.
打印(在标准输出上)编译器支持的符合所有指定类和限定符的命令行选项说明。
These are the supported classes: //一些支持的类
'optimizers'
Display all of the optimization options supported by the compiler
//显示编译器支持的所有优化选项
'warnings'
Display all of the options controlling warning messages produced by the compiler.
//显示控制编译器生成警告消息的所有选项。
'target'
Display target-specifc options. Unlike the ‘--target-help’ option however,
target-specifc options of the linker and assembler are not displayed.
//显示目标特定选项。 与'--target-help'选项不同,链接器和汇编器的 target-specifc 选项是不显示的。
This is because those tools do not currently support the extended ‘--help=’ syntax.
//这是因为这些工具当前不支持扩展的 '--help=' 语法。
'params'
Display the values recognized by the ‘--param’ option.
//显示“--param”选项识别的值。
'language'
Display the options supported for language, where language is the name of one of
the languages supported in this version of GCC.
//显示语言支持的选项,其中language是此版本的GCC中支持的其中一种语言的名称
'common'
Display the options that are common to all languages.
//显示所有语言通用的选项。
These are the supported qualifiers:
//这些是支持的限定词:
'undocumented'
Display only those options that are undocumented.
//仅显示那些没有文档的选项。
'joined'
Display options taking an argument that appears after an equal sign in
the same continuous piece of text, such as: ‘--help=target’.
//显示选项,采用在同一连续文本中等号后出现的参数,例如:'--help=target'。
'separate'
Display options taking an argument that appears as a separate word following
the original option, such as: ‘-o output-file’.
//显示选项采用在原始选项之后显示为单独单词的参数,例如:'-o output-file'。
Thus for example to display all the undocumented target-specifc switches
supported by the compiler, use:
//因此,例如显示编译器支持的所有未记录 target-specifc 开关 使用:
--help=target,undocumented
The sense of a qualifier can be inverted by prefixing it with the ‘^’ character,
//限定词的含义可以通过用 '^' 字符前缀来反转
so for example to display all binary warning options
//例如显示所有二进制警告选项
(i.e., ones that are either on or off and that do not take an argument)
//(即,打开或关闭且不采用参数的二进制警告选项)
that have a description, use:
//可以描述为,使用:
--help=warnings,^joined,^undocumented
The argument to ‘--help=’ should not consist solely of inverted qualifiers.
//'--help ='的参数不可以仅由 '^' 限定符组成。
Combining several classes is possible,
although this usually restricts the output so much that there is nothing to display.
//组合几类是可以的,尽管这通常会限制输出以至于无法显示。
One case where it does work, however,is when one of the classes is target.
//然而,其中一个类是目标的情况是可以的。
For example, to display all the target-specifc optimization options, use:
//例如,要显示所有 target-specifc 的优化选项,请使用:
--help=target,optimizers
The ‘--help=’ option can be repeated on the command line.
//'--help=' 选项可以在命令行中重复。
Each successive use displays its requested class of options,
skipping those that have already been displayed.
//每个连续使用显示其所请求的类别的选项,跳过已经显示的选项。
If the ‘-Q’ option appears on the command line before the ‘--help=’ option,
then the descriptive text displayed by ‘--help=’ is changed.
//如果命令行上在'-help='选项之前出现'-Q'选项,那么'--help='显示的描述性文本会被改变。
Instead of describing the displayed options,
an indication is given as to whether the option is enabled, disabled or set to a specifc value (assuming that the compiler knows this at the point where the ‘--help=’ option is used)
//不是描述显示的选项,而是给出了该选项是启用,禁用还是设置为特定值的指示(假设编译器在使用'--help='选项的时候知道这一点)
Here is a truncated example from the ARM port of gcc:
//这是gcc的ARM端口的截断示例
% 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-line options,
so for example it is possible to find out which optimizations are enabled at ‘-O2’ by using:
//输出对以前的命令行选项的影响很敏感,因此,例如,可以通过使用以下方式找出在“-O2”中启用哪些优化:
-Q -O2 --help=optimizers
Alternatively you can discover which binary optimizations are enabled by ‘-O3’ by using:
//或者,您可以通过使用以下方式来发现“-O3”启用哪些二进制优化:
gcc -c -Q -O3 --help=optimizers > /tmp/O3-opts
gcc -c -Q -O2 --help=optimizers > /tmp/O2-opts
--version
Display the version number and copyrights of the invoked GCC.
显示调用的GCC的版本号和版权
-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.
如果编译器的任何阶段返回一个非成功的返回码, 通常, gcc返回1并退出程序
If you specify ‘-pass-exit-codes’, the gcc program instead returns with the numerically highest error produced by any phase returning an error indication.
如果指定 ‘-pass-exit-codes’,gcc程序将返回任何阶段产生的数字最高的错误。
The C, C++, and Fortran front ends return 4 if an internal compiler error is encountered.
如果遇到内部编译器错误,C,C ++和Fortran的前端将返回4。
-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.
但是GNU汇编器是没有问题的
-specs=file
Process file after the compiler reads in the standard ‘specs’ file,
编译器读入标准“specs”文件后,
in order to override the defaults which the gcc driver program uses when determining what switches to pass to cc1, cc1plus, as, ld, etc.
More than one ‘-specs=file’can be specifed on the command line, and they are processed in order, from left to right.
可以在命令行中指定多个’-specs = file’,并按顺序从左到右处理。
See Section 3.19 [Spec Files], page 380, for information about the format of the file.
有关文件格式的信息,请参见第3.19节[规格文件],第380页。
-wrapper
Invoke all subcommands under a wrapper program.
调用 wrapper 程序的指令
The name of the wrapper program and its parameters are passed as a comma separated list.
wrapper 程序的名称及其参数以逗号分隔的列表形式传递。
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 …’.
这将调用gcc下的所有子程序 ‘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 purposes of argument parsing (See ‘-fplugin-arg-name-key=value’ below).
共享对象文件的基本名称用于标识插件以进行参数解析(参见下面的 ‘-fplugin-arg-name-key = value’)。
Each plugin should define the callback functions specifed in the Plugins API.
每个插件应该定义插件API中指定的回调函数。
-fplugin-arg-name-key=value
Define an argument called key with a value of value for the plugin called name.
定义一个名为key的参数,其值为名为name的插件。
-fdump-ada-spec[-slim]
For C and C++ source and include files, generate corresponding Ada specs.
对于C和C ++源代码和include文件,生成相应的Ada规范。
See Section ‘Generating Ada Bindings for C and C++ headers’ in GNAT User’s Guide, which provides detailed documentation on this feature.
请参见“GNAT用户指南”中的“为C和C ++标头生成Ada绑定”一节,其中提供了有关此功能的详细文档。
-fada-spec-parent=unit
In conjunction with ‘-fdump-ada-spec[-slim]’ above, generate Ada specs as child units of parent unit.
结合上述
'-fdump-ada-spec [-slim]'
,生成Ada规范作为父单元的子单位。
-fdump-go-spec=file
For input files in any language, generate corresponding Go declarations in file.
对于任何语言的输入文件,在文件中生成相应的Go声明。
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.
这会生成Go 常量,类型,变量,和方法声明,这对于开始用其他语言给 Go 编写接口是很有用的
@file
Read command-line options from file. The options read are inserted in place of the original @file option.
从文件读取命令行选项。 读取的选项将插入到原@file选项的位置。
If file does not exist, or cannot be read, then the option will be treated literally, and not removed.
如果文件不存在或无法读取,则将该选项作为
literally
来对待,而不会被删除。
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.
该文件本身也可能包含@file选项; 任何这样的选项将被递归处理。