Pre-translation head before World life

Source: Internet
Author: User

Precompiled header File Description

TAG: Pre-compilation and macro definition, VC + +, precompiled Header File Description text: The so-called header file pre-compilation, is a project (project) used in some of the MFC standard header files (such as Windows.H, Afxwin.H) pre-compile, later when the project compiles, This part of the header file is no longer compiled, only the precompiled results are used. This can speed up compilation and save time.Precompiled header files are generated by default by compiling Stdafx.cpp,named after the project name, the compiled result file is projectname.pch because the suffix for precompiled header files is "PCH".The compiler uses a precompiled header file through a header file StdAfx.h。 StdAfx.h This header file name can be specified in the compilation settings of Project. The compiler believes thatall code before the directive # include "StdAfx.h" is precompiled and skips the # include "StdAfx. H "Directive, use PROJECTNAME.PCH to compile all the code after this instruction. Soall CPP implementation files The first statement is: #include "stdafx.h"。

VC + + Pre-compile function

TAG: Precompiled and Macro definitions, vc++,vc++ pre-compilation features text: Here is the introduction of the use of VC6 precompiled features, due to the complexity of pre-compiling detailed use of the comparison, here are only a few of the most important pre-compilation instructions:/yu,/yc,/yx,/fp. Other details can be found at: MSDN, Visual Studio 6.0 document, Visual C + + 6.0 document,VC + + Programmer Guider->compiler and Linker, Details, Creating precompiled Header filesPrecompiled header concept: the so-called precompiled header is a part of the code in a project, pre-compiled and placed in a file (usually with a. pch extension), this file is called Precompiled header file these pre-compiled code can be any C + + code, or even inline functions, But it has to be stable and will not be changed frequently in the process of engineering development. If the code is modified, you will need to recompile the build precompiled header file. Note It is time consuming to generate precompiled header files. Also note that precompiled header files are usually large, usually 6-7m.   Be careful to clean up the unused precompiled header files in a timely manner. You may ask: Now the compiler has the function of time stamp, when the compiler compiles the entire project, it compiles only those files that have been modified, not those that have not been modified since the last compilation. So why precompile the header file? The answer here, we know that the compiler is compiled in a file, a file has been modified, will recompile the entire file, of course, in this file contains all the header files (. eg Macro, preprocessor) to be processed again. VC's precompiled header file is exactly this part of the information saved.   To avoid having to re-process the header files every time. As described above,the role of the precompiled header file is of course to improve the speed of the cheap, with it you do not need to compile every time that do not need to change the code. The compilation performance is of course improved. to use a precompiled header, we have to specify a header file that contains the code and other header files that we will not change frequently, and then we use this header file to generate a precompiled header file (. pch file) and presumably everyone knows StdAfx.h this file. Many people think that this is a "system level" provided by the VC, the compiler with a header file. Not really, this file can be any name. Let's examine a typical precompiled header file for the MFC Dialog Based program generated by AppWizard. (Because AppWizard will give us a good way to use the precompiled header file, the default is StdAfx.h, which is the name of VC). We will find this header file contains the following header files: #include <afxwin.h>//MFC Core and Standard Components#include <afxext.h>//MFC Extens Ions#include <afxdisp.h>//MFC Automation Classes#include <afxdtctl.h>//MFC support for Internet Explorer 4   Common Controls#include <afxcmn.h> These are the headers that must be included with MFC, and of course we are unlikely to modify these header files in our project, so that they are stable. So how do we specify it to generate precompiled header files. We know that a header file is not compiled.so we also need a CPP file to generate the. pch file. The default for this file is StdAfx.cpp.。in this file there is only one code: #include "Stdafx.h"。 The reason is that we just want it to compile--that is, it's just the. cpp extension. We can use the/yc compile switch to specify StdAfx.cpp to generate a. pch file, specifying the name of the generated PCH file by/fp the compile switch. Open the Project->setting->c/c++ dialog box. Point the category to the precompiled Header. Select the entire project in the tree view on the left, project options (the white place in the lower-right corner) to see the/fp "debug/pch.pch", which is the name of the. PCH file that you specified, which is usually the default < project name &GT;.PCH. And thenSelect StdAfx.cpp in the tree view on the left, when the original project option becomes Source file option (originally a project, now a file, of course, changed). Here we can see the/yc switch, the role of/yc is to specify this file to create a PCH file. The file name behind/yc is the header file that contains the stable code, and only one file can have a YC switch in a project. VC compiles StdAfx.cpp into an obj file and a PCH file based on this option. In this way, we set up the precompiled header file. In other words, we can use the precompiled header feature. Here are a few things to note: 1) If/yu is used, that is, precompilation is used, we start at the very beginning of each. cpp file, including the. h file you specified to produce the PCH file (default is stdafx.h) or there will be a problem.   If you do not include this file, you will be told unexpected file end. 2) If you accidentally lost the PCH file, according to the above analysis, you just have to let the compiler generate a PCH file. That is, the stdafx.cpp (that is, the CPP file of the specified/yc) will be recompiled again. FAQ: 1. The build. PCH is not set, but it is use2. The newly added CPP does not have an # include "stdafx.h" and can only be in the first line of code http://blog.csdn.net/lizheng308/article/ details/6914424

Pre-translation head before World life

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.