. C file compilation process

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.