Download gcc and gcc
The one-step command for gcc to compile source files is
$ Gcc demo. c-o demo
In fact, this step includes four steps:
1. Preprocessing
$ Gcc-E demo. c demo. I
The Preprocessing function mainly includes macro definition, file inclusion, and Conditional compilation. Corresponding to macro-defined commands. The file contains commands and Conditional compilation commands. The Preprocessing process reads the source code, checks the statements and macro definitions that contain the preprocessing commands, and converts the source code. The pre-processing process also deletes comments and extra spaces in the program.
The pre-processing command starts. # It must be the first character of the row except for any blank characters. # Followed by the command keyword. Any number of blank characters can exist between the keyword and. A full-line statement constitutes a preprocessing command that converts the source code before the compiler compilation.
2. Compile(Compile as assembly code)
$ Gcc-S demo. I-o demo. s
3. Assembly
$ Gcc-c demo. s-o demo. o
The gas assembler compiles the assembly code into the target file.
4. Links
$ Gcc demo. o demo
The gcc connector is provided by gas and is responsible for connecting the program's target file with all the required additional target files to generate executable files. Additional target files include static and dynamic connection libraries.
Multi-file Compilation:
$ Gcc demo1.c demo2.c-o demo