本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
结合"hello world"探讨gcc编译程序的过程
1. gcc简介
gcc/g++是GNU工程的C和C++编译器。都要用四个步骤中的一个或多个处理输入文件。
· 预处理(preprocessing)
· 编译(compilation)
· 汇编(assembly)
· 连接(linking)
源文件后缀名标识源文件的语言,但是对编译器来说,后缀名控制着缺省设定。
gcc命令的一般格式为:gcc [选项] 要编译的文件 [选项] [目标文件]
gcc的详细内容,可参考gcc manual。
2. gcc的输出选项
gcc输出选项,-o后指定输出文件名,gcc解释如下。
`-o FILE' Place output in file FILE. This applies regardless 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.
|
指定输出文件为FILE,该选项不考虑GCC产生什么输出,无论是可执行文件、目标文件、汇编文件还是预处理后的C代码。 如果没有使用`-o'选项,默认的输出结果是:可执行文件为a.out,source.suffix的目标文件是source.o,汇编文件是source.s,而预处理后的C代码送往标准输出。 |
3. "hello wolrd"的处理过程
本文以"hello world"程序,探讨GCC编译程序的过程。
hello.c文件内容如下。
#include <stdio.h>
int main(int argc, char **argv) { printf("Hello World! via %x/n", printf); return 0; } |
3.1 预处理