C + + compilation linking process

Source: Internet
Author: User

Compile and link are the two steps that most languages generate executable programs from the original code.

All of them have these two steps because almost any program is not written in a single original file. Compile is processed first for a separate original file. Link is to combine the results of compile processing into a complete executable file.

In fact, C + + can be completely one-step molding, do not need compile and link two steps, but the consequence is: one, every time to generate executable program, must translate all the source code; second, the C Language execution library (printf, scanf these) must be in the form of source code. How can it be justified?

Another header file is not part of the compile and link process, and the header file is a precompiled process file.

The complete compilation process for C + + language is

First, pre-compilation

The statements that handle the start of # define #if #include这类 # are called precompiled directives. In this process, the. h file and the. c/.cpp file are combined into the original files that are ultimately handed to the compile process. This original file is a statement that does not contain any of the # starts. All macros defined by # define are also replaced.

Second, compile
Compile the original file above to. O or VC is the. obj file. This file preserves the function of the machine code, the description of the function, the description of the global variable, and even the description of the segment.

Third, the connection
Combine the. o or. obj files that are generated by all the compilation processes required by the executable. (This also includes the. lib file, where the. lib file is essentially a packaged. obj file collection). In addition, the connection process also combines some other data, such as resources, executable headers, and so on.

C + + compilation linking process

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.