Content: This section is mainly used to introduce the use of gcc compiler.
table of Contents:
1. The four stages of gcc compilation
stage | command | Features |
---|---|---|
Precompiled | gcc -E hello.c -o hello.i |
1. Header file expansion 2. Macro replacement 3. De-comment |
Compile | gcc -S hello.i -o hello.s |
The c file is compiled into an assembly file |
compilation | gcc -c hello.s -o hello.o |
Turn assembly files into binary files |
link | gcc hello.o -o hello |
Link .o files and library files |
There are four stages of gcc compilation:
.c files are pre-compiled into .s files, .s files are compiled into .i files, .i files are assembled into .o files, and finally the .o files and library files are linked to generate executable file.
One step in place: The
default is to automatically call upwards, so the above steps can be automatically invoked by using the link command, so it can be completed in one step to generate an executable file.
gcc hello.c -o hello
Similarly, the assembly command can also be called upwards, and the .o file can be generated in one step.
gcc -c hello.c -o hello.o
2.gcc related commands
command | Features | example |
---|---|---|
-I | Specify header file location | gcc hello.c -I ./include |
-The | Specify the name of the output file | gcc hello.c -o hello |
-D | Open macro at compile time | gcc hello.c -D DEBUG |
-THE | The optimization program (0-3) 3 is the optimization | gcc hello.c -O3 |
-Wall | Output warning message | gcc hello.c -Wall |
-g | Add debugging information when compiling for subsequent gdb debugging | gcc hello.c -g |
Tips: Very simple things, just some commands, forgot to take a look.