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