查看GCC手册
GCC手册在线阅读
GCC手册英文pdf版本
GCC手册中文pdf版本
C语言中文网的GCC简介
查看gcc版本
#gcc -v
gcc支持的文件
gcc编译过程
编译过程并不是一步到位的,分为预编译、编译、汇编、链接。
预处理:源文件.c --> 处理后的源文件.i
编译:源文件.i --> 汇编文件.s
汇编:汇编文件.s -->目标文件.o
链接:可重定位目标文件.o --> 可执行目标文件(ELF)
但是如果直接gcc hello.c
,就会“直接”生成一个可执行文件a.out
,其实中间的过程还是会包括预处理、编译、汇编、链接四个过程,只不过是在内部实现了。
那平时为什么不直接生成执行文件?
- GNU的思想:一个工具只干一件事情
- 计算机工业思维:标准接口+分层
- 简化编译器的工作、提高工具的复用性
- 适配更多的平台、CPU架构、指令集
gcc的常用选项
#gcc --help
zhouyuanlin@zhouyuanlin-virtual-machine:/mnt/hgfs/share$ gcc --help
Usage: gcc [options] file...
Options:
-pass-exit-codes Exit with highest error code from a phase
--help Display this information
--target-help Display target specific command line options
--help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
Display specific types of command line options
(Use '-v --help' to display command line options of sub-processes)
--version Display compiler version information
-dumpspecs Display all of the built in spec strings
-dumpversion Display the version of the compiler
-dumpmachine Display the compiler's target processor
-print-search-dirs Display the directories in the compiler's search path
-print-libgcc-file-name Display the name of the compiler's companion library
-print-file-name=<lib> Display the full path to library <lib>
-print-prog-name=<prog> Display the full path to compiler component <prog>
-print-multiarch Display the target's normalized GNU triplet, used as
a component in the library path
-print-multi-directory Display the root directory for versions of libgcc
-print-multi-lib Display the mapping between command line options and
multiple library search directories
-print-multi-os-directory Display the relative path to OS libraries
-print-sysroot Display the target libraries directory
-print-sysroot-headers-suffix Display the sysroot suffix used to find headers
-Wa,<options> Pass comma-separated <options> on to the assembler
-Wp,<options> Pass comma-separated <options> on to the preprocessor
-Wl,<options> Pass comma-separated <options> on to the linker
-Xassembler <arg> Pass <arg> on to the assembler
-Xpreprocessor <arg> Pass <arg> on to the preprocessor
-Xlinker <arg> Pass <arg> on to the linker
-save-temps Do not delete intermediate files
-save-temps=<arg> Do not delete intermediate files
-no-canonical-prefixes Do not canonicalize paths when building relative
prefixes to other gcc components
-pipe Use pipes rather than intermediate files
-time Time the execution of each subprocess
-specs=<file> Override built-in specs with the contents of <file>
-std=<standard> Assume that the input sources are for <standard>
--sysroot=<directory> Use <directory> as the root directory for headers
and libraries
-B <directory> Add <directory> to the compiler's search paths
-v Display the programs invoked by the compiler
-### Like -v but options quoted and commands not executed
-E Preprocess only; do not compile, assemble or link
-S Compile only; do not assemble or link
-c Compile and assemble, but do not link
-o <file> Place the output into <file>
-pie Create a position independent executable
-shared Create a shared library
-x <language> Specify the language of the following input files
Permissible languages include: c c++ assembler none
'none' means revert to the default behavior of
guessing the language based on the file's extension
Options starting with -g, -f, -m, -O, -W, or --param are automatically
passed on to the various sub-processes invoked by gcc. In order to pass
other options on to these processes the -W<letter> options must be used.
For bug reporting instructions, please see:
<file:///usr/share/doc/gcc-5/README.Bugs>.
方便大家查看,这里找了一个翻译版本。
-pass-exit-codes 在某一阶段退出时返回最高的错误码
--help 显示此帮助说明
--target-help 显示目标机器特定的命令行选项
--help={target|optimizers|warnings|params|[^]{joined|separate|
undocumented}}[,...] //显示特定类型的命令行选项
(使用‘-v --help’显示子进程的命令行参数)
--version 显示编译器版本信息
-dumpspecs 显示所有内建 spec 字符串
-dumpversion 显示编译器的版本号
-dumpmachine 显示编译器的目标处理器
-print-search-dirs 显示编译器的搜索路径
-print-libgcc-file-name 显示编译器伴随库的名称
-print-file-name=<库> 显示 <库> 的完整路径
-print-prog-name=<程序> 显示编译器组件 <程序> 的完整路径
-print-multi-directory 显示不同版本 libgcc 的根目录
-print-multi-lib 显示命令行选项和多个版本库搜索路径间的映射
-print-multi-os-directory 显示操作系统库的相对路径
-print-sysroot 显示目标库目录
-print-sysroot-headers-suffix 显示用于寻找头文件的 sysroot 后缀
-Wa,<选项> 将逗号分隔的 <选项> 传递给汇编器
-Wp,<选项> 将逗号分隔的 <选项> 传递给预处理器
-Wl,<选项> 将逗号分隔的 <选项> 传递给链接器
-Xassembler <参数> 将 <参数> 传递给汇编器
-Xpreprocessor <参数> 将 <参数> 传递给预处理器
-Xlinker <参数> 将 <参数> 传递给链接器
-combine 将多个源文件一次性传递给汇编器
-save-temps 不删除中间文件
-save-temps=<arg> 不删除中间文件
-no-canonical-prefixes 生成其他 gcc 组件的相对路径时不生成规范化的
前缀
-pipe 使用管道代替临时文件
-time 为每个子进程计时
-specs=<文件> 用 <文件> 的内容覆盖内建的 specs 文件
-std=<标准> 指定输入源文件遵循的标准
--sysroot=<目录> 将 <目录> 作为头文件和库文件的根目录
-B <目录> 将 <目录> 添加到编译器的搜索路径中
-b <机器> 为 gcc 指定目标机器(如果有安装)
-V <版本> 运行指定版本的 gcc(如果有安装)
-v 显示编译器调用的程序
-### 与 -v 类似,但选项被引号括住,并且不执行命令
-E 仅作预处理,不进行编译、汇编和链接
-S 编译到汇编语言,不进行汇编和链接
-c 编译、汇编到目标代码,不进行链接
-o <文件> 输出到 <文件>
-x <语言> 指定其后输入文件的语言,允许的语言包括:c c++
assembler none‘none’意味着恢复默认行为,即根据文件的扩展名猜测源文件的语
言
以 -g、-f、-m、-O、-W 或 --param 开头的选项将由 g++/gcc 自动传递给其调用的
不同子进程。若要向这些进程传递其他选项,必须使用 -W<字母> 选项。
通过gcc --help
可以查看gcc的选项,主语区分大小写。不过其实常用的也就是十多个选项。