GCC manual-RTFM
今天心血来潮想要拜读gcc
man page,学到很多。有时候会思考,AI确实帮助了我快速上手一个领域,比如使用Rust编写一个植物大战僵尸的游戏,比如从零开始认识一个代码,但是一旦结束之后,回头再想就很难说我仍然可以再举一反三地做另一个好玩的事情,事实上Rust的语法和特性我也几乎忘记。
jyy老师在课堂上曾经向我们展示了许多很好玩的代码,很有意思的命令行,也曾经嘱咐我们一定要RTFM(Read The Friendly Manual),现在的我毕业了,同时仍然是AI的重度依赖者,只是心里一直有一个地方在不断的问自己:AI的回答能否坦然接受?
我的答案一直是:NO
我始终在拥抱AI的同时留有一丝怀疑和谨慎。
这是man page的部分内容,权当记录,明天还要更新更多的笔记。
NAME
gcc - GNU project C and C++ compiler
gcc [-c|-S|-E] [-std=standard]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-Wpedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...] [-mmachine-option...]
[-o outfile] [@file] infile...
Only the most useful options are listed here; see below for the
remainder. g++ accepts mostly the same options as gcc.
DESCRIPTION
When you invoke GCC, it normally does preprocessing, compilation,
assembly and linking. The "overall options" allow you to stop
this process at an intermediate stage. For example, the -c option
says not to run the linker. Then the output consists of object
files output by the assembler.
Other options are passed on to one or more stages 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.
The usual way to run GCC is to run the executable called gcc, or
machine-gcc when cross-compiling, or machine-gcc-version to run a
specific version of GCC. When you compile C++ programs, you
should invoke GCC as g++ instead.
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: -dv is very different from -d -v.
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. Also, the placement of the -l option is significant.
Many options have long names starting with -f or with -W---for
example, -fmove-loop-invariants, -Wformat and so on. Most of
these have both positive and negative forms; the negative form of
-ffoo is -fno-foo. This manual documents only one of these two
forms, whichever one is not the default.
Some options take one or more arguments typically separated either
by a space or by the equals sign (=) from the option name. Unless
documented otherwise, an argument can be either numeric or a
string. Numeric arguments must typically be small unsigned
decimal or hexadecimal integers. Hexadecimal arguments must begin
with the 0x prefix. Arguments to options that specify a size
threshold of some sort may be arbitrarily large decimal or
hexadecimal integers followed by a byte size suffix designating a
multiple of bytes such as "kB" and "KiB" for kilobyte and
kibibyte, respectively, "MB" and "MiB" for megabyte and mebibyte,
"GB" and "GiB" for gigabyte and gigibyte, and so on. Such
arguments are designated by byte-size in the following text.
Refer to the NIST, IEC, and other relevant national and
international standards for the full listing and explanation of
the binary and decimal byte size prefixes.
Option Summary
Here is a summary of all the options, grouped by type.
Explanations are in the following sections.
Overall Options
-c -S -E -o file -x language -v -###
--help[=class[,...]] --target-help --version
-pass-exit-codes -pipe -specs=file -wrapper @file
-ffile-prefix-map=old=new -fplugin=file -fplugin-arg-name=arg
-fdump-ada-spec[-slim] -fada-spec-parent=unit
-fdump-go-spec=file
C Language Options
-ansi -std=standard -fgnu89-inline
-fpermitted-flt-eval-methods=standard -aux-info filename
-fallow-parameterless-variadic-functions -fno-asm
-fno-builtin -fno-builtin-function -fgimple -fhosted
-ffreestanding -fopenacc -fopenacc-dim=geom -fopenmp
-fopenmp-simd -fms-extensions -fplan9-extensions
-fsso-struct=endianness -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 -faligned-new=n
-fargs-in-order=n -fchar8_t -fcheck-new -fconstexpr-depth=n
-fconstexpr-loop-limit=n -fconstexpr-ops-limit=n
-fno-elide-constructors -fno-enforce-eh-specs
-fno-gnu-keywords -fno-implicit-templates
-fno-implicit-inline-templates -fno-implement-inlines
-fms-extensions -fnew-inheriting-ctors -fnew-ttp-matching
-fno-nonansi-builtins -fnothrow-opt -fno-operator-names
-fno-optional-diags -fpermissive -fno-pretty-templates -frepo
-fno-rtti -fsized-deallocation -ftemplate-backtrace-limit=n
-ftemplate-depth=n -fno-threadsafe-statics -fuse-cxa-atexit
-fno-weak -nostdinc++ -fvisibility-inlines-hidden
-fvisibility-ms-compat -fext-numeric-literals -Wabi=n
-Wabi-tag -Wconversion-null -Wctor-dtor-privacy
-Wdelete-non-virtual-dtor -Wdeprecated-copy
-Wdeprecated-copy-dtor -Wliteral-suffix -Wmultiple-inheritance
-Wno-init-list-lifetime -Wnamespaces -Wnarrowing
-Wpessimizing-move -Wredundant-move -Wnoexcept
-Wnoexcept-type -Wclass-memaccess -Wnon-virtual-dtor
-Wreorder -Wregister -Weffc++ -Wstrict-null-sentinel
-Wtemplates -Wno-non-template-friend -Wold-style-cast
-Woverloaded-virtual -Wno-pmf-conversions
-Wno-class-conversion -Wno-terminate -Wsign-promo
-Wvirtual-inheritance
Preprocessor Options
-Aquestion=answer -A-question[=answer] -C -CC -Dmacro[=defn]
-dD -dI -dM -dN -dU -fdebug-cpp -fdirectives-only
-fdollars-in-identifiers -fexec-charset=charset
-fextended-identifiers -finput-charset=charset
-fmacro-prefix-map=old=new -fno-canonical-system-headers
-fpch-deps -fpch-preprocess -fpreprocessed -ftabstop=width
-ftrack-macro-expansion -fwide-exec-charset=charset
-fworking-directory -H -imacros file -include file -M -MD
-MF -MG -MM -MMD -MP -MQ -MT -no-integrated-cpp -P
-pthread -remap -traditional -traditional-cpp -trigraphs
-Umacro -undef -Wp,option -Xpreprocessor option
Assembler Options
-Wa,option -Xassembler option
Linker Options
object-file-name -fuse-ld=linker -llibrary -nostartfiles
-nodefaultlibs -nolibc -nostdlib -e entry --entry=entry
-pie -pthread -r -rdynamic -s -static -static-pie
-static-libgcc -static-libstdc++ -static-libasan
-static-libtsan -static-liblsan -static-libubsan -shared
-shared-libgcc -symbolic -T script -Wl,option -Xlinker
option -u symbol -z keyword
Directory Options
-Bprefix -Idir -I- -idirafter dir -imacros file -imultilib
dir -iplugindir=dir -iprefix file -iquote dir -isysroot dir
-isystem dir -iwithprefix dir -iwithprefixbefore dir -Ldir
-no-canonical-prefixes --no-sysroot-suffix -nostdinc
-nostdinc++ --sysroot=dir
Code Generation Options
-fcall-saved-reg -fcall-used-reg -ffixed-reg -fexceptions
-fnon-call-exceptions -fdelete-dead-exceptions
-funwind-tables -fasynchronous-unwind-tables -fno-gnu-unique
-finhibit-size-directive -fno-common -fno-ident
-fpcc-struct-return -fpic -fPIC -fpie -fPIE -fno-plt
-fno-jump-tables -frecord-gcc-switches -freg-struct-return
-fshort-enums -fshort-wchar -fverbose-asm -fpack-struct[=n]
-fleading-underscore -ftls-model=model
-fstack-reuse=reuse_level -ftrampolines -ftrapv -fwrapv
-fvisibility=[default|internal|hidden|protected]
-fstrict-volatile-bitfields -fsync-libcalls
For any given input file, the file 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.
file.mii
Objective-C++ source code that should not be preprocessed.
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.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.mm
file.M
Objective-C++ source code that must be preprocessed.
file.mii
Objective-C++ source code that should not be preprocessed.
file.hh
file.H
file.hp
file.hxx
file.hpp
file.HPP
file.h++
file.tcc
C++ header file 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 should not be preprocessed.
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.d
D source code.
file.di
D interface file.
file.dd
D documentation code (Ddoc).
file.ads
Ada source code file 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 files are also called specs.
file.adb
Ada source code file containing a library unit body (a
subprogram or package body). Such files are also called
bodies.
file.s
Assembler code.
file.S
file.sx
Assembler code that must be preprocessed.
other
An 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:
-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:
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
d
f77 f77-cpp-input f95 f95-cpp-input
go
brig
-x none
Turn off any specification 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).
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. Note that some
combinations (for example, -x cpp-output -E) instruct gcc to do
nothing at all.
-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 produced, whether it be an executable file, an
object file, an assembler 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 source.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.
--help
Print (on the standard output) a description of the command-
line options understood 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.
--target-help
Print (on the standard output) a description of target-
specific command-line options for each tool. For some targets
extra target-specific 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-specific options. Unlike the --target-help
option however, target-specific options of the linker and
assembler are not displayed. This is because those tools
do not currently support the extended --help= syntax.
params
Display the values recognized by the --param option.
language
Display the options supported for language, where language
is the name of one of the languages supported in this
version of 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.
separate
Display options taking an argument that appears as a
separate word following the original option, such as: -o
output-file.
Thus for example to display all the undocumented target-
specific switches 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 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.
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-
specific optimization options, use:
--help=target,optimizers
The --help= option can be repeated on the command line. Each
successive use displays its requested class of options,
skipping those that have already been displayed. If --help is
also specified anywhere on the command line then this takes
precedence over 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 displayed options, an
indication is given as to whether the option is enabled,
disabled or set to a specific value (assuming that the
compiler knows this at the point where the --help= option is
used).
Here is a truncated example from the ARM port of gcc:
% 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:
-Q -O2 --help=optimizers
Alternatively you can discover which binary optimizations are
enabled by -O3 by using:
gcc -c -Q -O3 --help=optimizers > /tmp/O3-opts
gcc -c -Q -O2 --help=optimizers > /tmp/O2-opts
diff /tmp/O2-opts /tmp/O3-opts | grep enabled
--version
Display the version number and copyrights of the invoked 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. 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.
-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.
-specs=file
Process file after the compiler reads in the standard specs
file, 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
specified on the command line, and they are processed in
order, from left to right.
-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 ....
-ffile-prefix-map=old=new
When compiling files residing in directory old, record any
references to them in the result of the compilation as if the
files resided in directory new instead. Specifying this
option is equivalent to specifying all the individual
-f*-prefix-map options. This can be used to make reproducible
builds that are location independent. See also
-fmacro-prefix-map and -fdebug-prefix-map.
-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). Each plugin should define the callback functions
specified in the Plugins API.
-fplugin-arg-name-key=value
Define an argument called key with a value of value for the
plugin called name.
-fdump-ada-spec[-slim]
For C and C++ source and include files, generate corresponding
Ada specs.
-fada-spec-parent=unit
In conjunction with -fdump-ada-spec[-slim] above, generate Ada
specs as child units of parent unit.
-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.