Gcc Compilation 1 file type cC original program o target file h header file I pre-processed C original
Gcc Compilation
1. file type
. C C original program
. O target file
. H header file
. I pre-processed C raw file
. Ii pre-processed C ++ raw files
. A compiled static library file
. So compiled dynamic library file
Static library: all the code of the library file is added to the executable file when the link is compiled. the file is large and the library file is required for running.
Dynamic library: links files to load the library when the program runs, saving system overhead
2. Gcc compilation process
(1). Pre-compile
Gcc-E linux. c-o linux. I
Gcc [option] file [option] target file
Note: The target file can be defaulted.
Before pre-compilation:
After pre-compilation:
Compare the differences between the two files to get the pre-compilation work:
1) import: delete# IncludeAnd add the content of stdio. h to the program to respond to it,
2) replacement: poor deletion# DefineAnd replace all PI of the file with the specified value.
3)Replace the comment with a space character
4)DeleteSomeUnnecessary spaces
Ps: this. I file helps debug the error program
2. Compile
1) check the code normalization and syntax errors
2) translate into assembly code
3. Assembly
Is to convert the assembly code to the binary target code of ". o,
4. links
There is no function printf implementation in the source file. even in the pre-compiled file, only the printf function declaration is available, and the system places these functions in libc. so.6 is included in the library file, without special settings, GCC will go to the system's default search path "/usr/lib", that is, link to libc. so.6 library files (loaded as dynamic libraries)
Finally generate an executable file
Command parameter description:
-E only performs pre-compilation without any additional processing.
Gcc-E linux. c-o linux. I
-O file: uploads the output to the file.
Gcc-S linux. I-o linux. s
-S is just for compilation without assembly, and the assembly code is generated
Gcc-c linux. s-o linux. o
-C: only compilation is not linked, and the target code is generated.
Gcc linux. o-o linux
The previous steps are step-by-step execution to illustrate the entire compilation process. if you want to output them in one step, you can:
Gcc linux. c-O output file