Pre-translated head file
Keywords: pre-compilation, / yu, / yc, / yx
This article describes the use of the pre-compiled function of VC6. Because the precompiled detailed use is complicated, only several of the most important precompiled instructions: / yu, / yc, / yx, / fp. Other details Approval: MSDN-> Visual Studio D6.0Document -> Visual C 6.0 Document -> VC Programmer Guider -> Compiler and Linker -> Details-> Creating Precompiled Header Files
Preparatory head concept:
The so-called pre-compiled head is the part of the part of the project, pre-compiling it in a file (usually as an extension of .pch), this file is called the pre-compiled header file these pre-compiled code. Can be any C / C code -------- even inline functions, but must be stable, will not change frequently during engineering development. If these codes are modified, you need to recompile to generate a precompiled header file. Note that generating the pre-translated head file is time consuming. At the same time, you have to pay attention to the pre-translated head files usually, usually 6-7m large. Be careful to clean up the unused preform files in time.
Maybe you will ask: There is a Time Stamp function, and the compiler is compiling the entire project, it will only compile the modified files without compiling those who have compiled from the last time. Modified file. So why do you want to pre-translate? The answer is here, we know that the compiler is compiled by the file. After a file is modified, it will recompile the entire file, of course, the things in all header files contained in this file (.eg macro, preprocessor) must Re-process it. This part of this section is saved for the pre-edged head file of the VC. To avoid restructuring these headers each time.
The role of the precompiled head:
Method 1: Manual method
According to the above, the role of the pre-translated head file is of course increasing, and it is not necessary to compile the code that does not require frequent changes. Compiling performance is of course improved.
Preparatory heads:
To use a pre-compiled head, we must specify a header file, this header file contains code we do not change frequently and other header files, and then we use this header to generate a pre-translated head file (.pch file)
I want everyone to know that this file is STDAFX.H. Many people think this is a "system level", a header file provided by VC, compiler. Actually, this file can be any name. Let's examine a typical pre-compiled head file for the MFC Dialog Based program generated by AppWizard. (Because AppWizard specifies how to use the pre-translated head file, the default is stdafx.h, this is the name of the VC). We will find the following header files in this header:
#include
#include
#include
#include
#include
So how do we specify it to generate a pre-translated header file. We know that a header file cannot be compiled. So we also need a CPP file to generate the .pch file. This file is stdafx.cpp by default. Only one code in this file is: #include "stdafx.h". The reason is reasonable, we just want it to be able to compile - that is, it is just its .cpp extension. We can use the / YC compilation switch to specify stdafx.cpp to generate a .pch file, to specify the name of the generated PCH file via / fp compilation switch. Open the Project -> Setting-> C / C dialog box. Point Category to Precompiled Header. Choose the entire project in the tree view on the left (Figure)
(Figure 1)
In the figure, our Project Options (the white place in the lower right corner) can see / fp "debug / pch.pch", which is the name of the generated .ph file, the default is usually
Then, select stdafx.cpp in the tree view on the left. As shown: (Figure 2)
At this time, the original Project Option became a Source File Option (originally a project, now a file, of course). Here we can see / YC switches, / YC's role is to specify this file to create a PCH file. / YC's file name is the header containing the stable code, and only one file can have a YC switch in one project. The VC compiles stdafx.cpp into an OBJ file and a PCH file based on this option.
Then we choose another file to see, as shown:
Here, Precomplier chose Use ........., the header file is stdafx.h we specified to create a PCH file.
file. In fact, here is the settings in the project, (Figure 1) / yu "stdafx.h".
In this way, we set up the pre-translated header file. That is, we can use the pre-compiled head function. The following is awareness:
1): If you use / yu, it is said that the precompiled transcription is used. We emphasize the most beginning in each .cpp file, I emphasize the most beginning, containing the .h file you specify the PCH file (default is stdafx.h Otherwise there will be a problem. If you don't include this file, you tell you UNEXPECTED FILE END. If you are not in the most beginning, you will know if you try it yourself, definitely an amazing effect .....
2) If you accidentally lose the PCH file, according to the above analysis, you just want the compiler to generate a PCH file. That is to say, stdafx.cpp is available from the new compilation from the new compilation. Of course you can silly rebuild all. Simple is to choose that CPP file, press CTRL F7.
Method Two. Automatic use
Very simple as long as you specify / yx. Or choose Automatic .... you can choose in the above figure. Note that if you specify / yu, / yx will be ignored. The priority of the former is higher.
Pan Li Liang
2002 9