When using GCC to compile a program, the compilation process can be subdivided into four stages:
- Pretreatment
The preprocessing process reads into the program source code, examines the statements and macro definitions that contain the preprocessing directives, and transforms the source code accordingly. The preprocessing process removes comments and extra white space characters from the program.
- Compile
In the compilation phase, GCC first checks the code's normative, whether there are grammatical errors, and so on, to determine the actual work of the code to do, after the check is correct, GCC translated the code into assembly language.
- Assembly
The assembly phase is to convert the assembly files generated during the compilation phase to the target code.
- Link
Link the compiled output file to the final executable binary file
Example:
vi hello.c#include <stdio.h>int main(){ printf("hello world"); return0;}
$ ls Hello. C$ GCC-E Hello. C-O Hello. I #预处理, output the preprocessed result as a hello.i file$ ls Hello. CHello. I$ gcc-s Hello. I #编译, compile the preprocessed results into a compilation file$ ls Hello. CHello. IHello. S$ gcc-c Hello. S #汇编, convert the assembly file into a target file$ ls Hello. CHello. IHello. OHello. S$ gcc Hello. O-O Hello#链接, connect the target file into a binary executable named Hello$ ls Hello hello. CHello. IHello. OHello. S
Procedures for Linux GCC compilers