Summary of the C file compilation process.
First, assume that there is such a classic CProgram:
# Include <stdio. h> int main () {printf ("Hello \ n"); Return 0 ;}
First, save the above program as a standard ASCII text file hello. C.
As a result, the system starts to process it like this:
The pre-processor starts to intervene to pre-process the file, that is, replace the text, and replace a lot of #, such as the # include <stdio. h>, replace it with the original stdio. H content, and save it. Now the name is hello. i, so the compiler is involved.
The compiler treats the hello. i. the content of I is translated from the C language into the assembly language instructions. You don't need to worry about how to do it for the time being. after learning the compilation principle, you will understand it.
The assembler then assembles the Assembly Language commands generated in the previous step to generate binary files, but they are only semi-finished products, because they have not linked functions in various files, etc. The file is hello. O.
Finally, the linker associates the target files related to each other. For example, if the program calls the printf function, the link must be a separately compiled printf. O files are processed in a variety of complicated ways. Only binary files that can be directly executed by machines are generated here. of course, the actual situation is often much more complicated than this, so I will not go into the details here.
The entire process of C language compilation is very complex, involving a lot of compiler knowledge, hardware knowledge, and tool chain knowledge, an in-depth understanding of the entire compilation process is of great help to engineers to understand the compilation of applications.