Through the previous article to take you to the visual studio--with your multiple engineering development, we are able to create multiple projects in a solution, unified management of a project for multiple project. In this article we will continue to explain Microsoft's precompiled header technology. no stranger stdafx.h.
Remember to show you around. Visual studio--take you to a new project. Figure 2 (copied to the following figure 1 for easy reading). We have checked the precompiled header checkbox by default, the created project automatically added stdafx.h and stdafx.cpp,stdafx.h is precompiled header file , tick precompiled The header indicates the use of Microsoft's precompiled header technology.
Figure 1:application Settings
turn on or off precompiled methods
Right-key project name->properties->configuration properties->c/c++->precompiled header,precompiled Header drop-down list box select Use (/ Yu) represents how to open (use) A precompiled header, and select not using precompiled headers to indicate how to turn off the precompiled header.
Figure 2: Setup of Precompiled headers
Parameter description:
Precompiled header: Whether the precompiled header is used;
Precompiled header file: The name of the precompiled header, the case of the file name in VS is not sensitive, but it is best to keep the case the same.
Precompiled Header Output file: the generated. pch file my name, about the. pch file will be described in the following precompiled principles section.
If you want to use a precompiled header file, you also need to set the properties of the Stdafx.cpp file. Right-stdafx.cpp->properties->configuration properties->c/c++->precompiled header,precompiled Header drop-down list box, select Create (Yc).
Figure 3: Setting the properties of. cpp
Attention Matters
the first line of code for each source file must contain a precompiled header file. If your project uses precompiled header files, the first line of code for each. cpp file must contain a precompiled header file (#include "stdafx.h"), or an error will be compiled. the memory principle of pre-compiling technology
When Windows programs are developed, it is often necessary to include standard headers such as Windows.h, Afx.h, and so on in individual files, which are very large, very slow at compile time, and time-consuming. To solve this problem, there is already the technology of precompiled header file.
The so-called header file Precompilation technology is to include in a project (project) commonly used header files (such as standard header file Windows.h, Afxwin.h, etc., can also be their own definition of the header file) included in the StdAfx.h, and StdAfx.h precompiled ( Compiled before all. cpp files are compiled), the compiled results. pch file (the default name is PROJECTNAME.PCH), and later, when the project compiles other. cpp files, it no longer compiles the contents of the stdafx.h (even if it includes it), Only the results of precompiling are used.
Where stdafx.h is called precompiled Header File , StdAfx name in English is all called: Standard application Framework Extensions, of course, you can also define the name of the precompiled header file, Manually rename the stdafx.h and also change the name corresponding to Figure 2 and figure 3 above. PROJECTNAME.PCH is called the precompiled header .
With precompiled header technology, you can speed up compilation and save compile time. Because it only needs to be precompiled once, it can be used at all. cpp compile time without recompiling. One problem with this is that every. cpp file starts with a precompiled header file #include "stdafx.h." because the precompiled header technique assumes that the contents of the precompiled header are used in all. cpp files, the compiled portion of the precompiled header is loaded into memory when you compile your. cpp.
Several important points to note when using precompiled header files are:
1. Any. cpp files that you write must first contain stdafx.h.
2. If you have the. h files required for most of the. cpp files in the engineering documents, add them to the stdafx.h (back), and then precompile the stdafx.cpp.
3. Because the. pch file has a large number of symbolic information, it is the largest file in your engineering document. How to use MFC libraries in Non-MFC projects
This part of the content has been written before, will not repeat, directly to the link:
MFC libraries used in non-MFC projects
Previous review:
I'll take you to the visual studio--to bring you multiple engineering development
What to tell in the next article:
Take you to play the visual studio--take you out of runtime library big Pit