Brief introduction
gcc means gun C Compiler. After years of development, GCC has not only supported the C language, it also now supports the ADA, C + +, Java, objective C, Pascal, COBOL, and Mercury languages that support functional programming and logical programming, and so on. And GCC is no longer simply gun the meaning of the C language compiler, but became a gun complier collection is also the meaning of the gun compiler family. On the other hand, when it comes to GCC's support for operating system platforms and hardware platforms, it is summed up in the same sentence: ubiquitous.
compiling
the sample program is as follows:
#include <stdio.h>
int main (void) {
printf ("Hello world!\n");
return 0;
}
This program, one-step's compilation instructions are:
In essence, the above compilation process is divided into four phases:
- Preprocessing (also known as precompilation, preprocessing)
- Compiling (Compilation)
- Compilation (Assembly)
- Connection (linking)
pretreatment
GCC-E test.c-o test.i or GCC-E test.c
You can output test.i files that contain test.c code that is preprocessed. Open the Test.i file and take a look at it and you'll see. The following instruction is to output the preprocessed code directly in the Command line window.
The-e option of GCC allows the compiler to stop after preprocessing and output preprocessing results. In this case, the preprocessing result is to insert the contents of the stdio.h file into the test.c.
Compile to assembly code
after preprocessing, you can compile the generated test.i file directly, generating assembly code:
The-s option of GCC, which means that when the assembly code is generated, the-O output assembly code file is stopped when the program is compiled
Assembly
for the assembly code file generated in the previous section, the Test.s,gas assembler is responsible for compiling it as the target file, as follows:
Connection
The GCC connectors are provided by gas and are responsible for connecting the target files of the program to all of the additional target files required, resulting in an executable file. Additional target files include static connection libraries and dynamic connection libraries.
For the TEST.O generated in the previous section, connect it to the C standard Input output library, and eventually build the program test
Executes in a command line window./test, let it say hello world!