C + +-Program compilation

Source: Internet
Author: User

Program compilation

The process of compiling the program can be divided into 4 steps, such as editing, preprocessing, compiling and linking.

1. Editing

Editor: The process of importing a source file into a computer for modification and saving is called "editing."

2. Preprocessing

A preprocessor is a stand-alone program that is called by the compiler before the actual compilation begins. The preprocessor can delete comments , include files , and perform macro overrides .

The preprocessor changes the program text before the compiler according to instructions. The compiler sees the code text that the preprocessor has modified.

"#include", "#define", etc. are all compiled preprocessing. Preprocessing lines end without semicolons. In principle the preprocessing line can be written anywhere in the program, but it is recommended to write in the file header. The common preprocessing directives are as follows:

1) header file contains, #include <iostream>

2) macro, #define PI 3.14

3) conditional compilation, #ifndef _func_h_ #define _FUNC_H_ #endif

4) Other, such as #pragma

3. Compiling

Compilation is used to translate each compilation unit into a binary code file. In DOS and Windows environments, the suffix of the binary code file is . obj, and in the UNIX environment, the prefix is named . O .

The object that the compiler handles is actually a compilation unit consisting of a single. cpp file and a header file that is recursively contained. When a. cpp file is compiled, the preprocessor first recursively contains the header file, forming a single source file containing all the necessary information, which is a compilation unit. This compilation unit is translated as a target file (. o or. obj) with the same name as the. cpp file.

Each. cpp file corresponds to a compilation unit, and each compilation unit generates a binary code file. Therefore, each. cpp file corresponds to a binary code file.

4. Links

The purpose of the linker is to combine the compiled fragmented binary code files into binary executables (. exe) files. It has two meanings:

1) Parse the functions and variables in the compilation unit;

2) Establish a link to the library function

A link is a procedure that assigns an absolute address to a function of a variable in a program, making the binaries executable.

  

C + +-Program compilation

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.