随笔-24  评论-79  文章-16  trackbacks-37

These files are used to build a precompiled header file Projname.pch and a precompiled types file Stdafx.obj.
这两个文件用于建立一个预编译的头文件Projename.pch和一个预定义的类型文件Stdafx.obj。

These files are located in the Projname directory. In Solution Explorer, Stdafx.h is in the Header Files folder, and Stdafx.cpp is located in the Source Files folder.
这两个文件放置在项目文件夹中。在解决方案管理器里,Stdafx.h位于Header Files文件夹,Stdafx.cpp则位于Source Files文件夹。

File name

Description

Stdafx.h

An include file for standard system include files and for project-specific include files that are used frequently but are changed infrequently.

You should not define or undefine any of the _AFX_NO_XXX macros in stdafx.h; see the Knowledge Base article "PRB: Problems Occur When Defining _AFX_NO_XXX". You can find Knowledge Base articles in the MSDN Library or at http://search.support.microsoft.com/.

Stdafx.cpp

Contains the preprocessor directive #include "stdafx.h" and adds include files for precompiled types. Precompiled files of any type, including header files, support faster compilation times by restricting compilation only to those files that require it. Once your project is built the first time, you will notice much faster build times on subsequent builds because of the presence of the precompiled header files.

 

From 可心

Stdfx 指 Standard Application Frame Extend。
由于MFC体系结构非常大,包含许多头文件,如果每次都编译的话比较费时。因此,我们把常用的MFC头文件都放在stdafx.h中,如afxwin.h、afxext.h、afxdisp.h、afxcmn.h等,然后让stdafx.cpp包含这个stdafx.h文件。这样,由于编译器可以识别哪些文件已经编译过,所以stdafx.cpp就只编译一次,并生成所谓的预编译头文件(因为它存放的是头文件编译后的信息,故名)。
        如果读者以后在编程时不想让有些MFC头文件每次都被编译,也可以将它加入到stdafx.h中。采用预编译头文件可以加速编译过程。

Windows和MFC的include文件都非常大,即使有一个快速的处理程序,编译程序也要花费相当长的时间来完成工作。由于每个.CPP文件都包含相同的include文件,为每个.CPP文件都重复处理这些文件就显得很傻了。
     为避免这种浪费,AppWizard和Visual C++编译程序一起进行工作,如下所示: 

  •      AppWizard建立了文件stdafx.h,该文件包含了所有当前工程文件需要的MFC include文件。且这一文件可以随被选择的选项而变化。 
  •      AppWizard然后就建立stdafx.cpp。这个文件通常都是一样的。 
  •      然后AppWizard就建立起工程文件,这样第一个被编译的文件就是stdafx.cpp。 
  •      当Visual C++编译stdafx.cpp文件时,它将结果保存在一个名为stdafx.pch的文件里。 (扩展名pch表示预编译头文件。)

  •      当Visual C++编译随后的每个.cpp文件时,它阅读并使用它刚生成的.pch文件。 Visual C++不再分析Windows include文件,除非你又编缉了stdafx.cpp或stdafx.h。 
         在这个过程中你必须遵守以下规则: 
  •      你编写的任何.cpp文件都必须首先包含stdafx.h。 
  •      如果你有工程文件里的大多数.cpp文件需要.h文件,顺便将它们加在stdafx.h (后部)上,然后预编译stdafx.cpp。 
         由于.pch文件具有大量的符号信息,它是你的工程文件里最大的文件。如果你的磁盘空间有限,你就希望能将这个你从没使用过的工程文件中的.pch文件删除。执行程序时并不需要它们,且随着工程文件的重新建立,它们也自动地重新建立。
posted on 2007-10-02 16:57 Hunts.C 阅读(417) 评论(0)  编辑 收藏 所属分类: C/C++

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-10-02 17:27 编辑过


相关链接: