Precompiled Header

开始学C++……

错误 2 error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?

于是有几个问题:

  1. 为什么VS需要查找预编译头?
  2. 添加一个头文件有啥用?而且stdafx.h里边没啥东西……
先贴上吧,以后再总结。下面来自维基百科

In the C and C++ programming languages, a header file is a file whose text may be automatically included in another source file by the C preprocessor by the use of a compiler directive in the source file.

Header files can sometimes contain very large amounts of source code (for instance, the header files windows.h and Cocoa/Cocoa.h on Microsoft Windows and Mac OS X, respectively). This is especially true with the advent of large 'header' libraries that make extensive use of templates, like the Eigen math library and the Boost (C++ libraries). They are written almost entirely as header files that the user #includes, rather than being linked at runtime. Thus each time the user compiles their program, they are essentially recompiling numerous header libraries as well that would ordinarily have been precompiled into shared objects or dynamic link libraries.

To reduce compilation times, some compilers allow header files to be compiled into a form that is faster for the compiler to process. This intermediate form is known as aprecompiled header, and is commonly held in a file named with the extension .pch or similar, such as .gch under the GNU Compiler Collection.

A related feature is the prefix header, which is a file that is automatically included by the compiler without requiring the use of any compiler directives. Prefix headers are commonly precompiled, but not all precompiled headers are prefix headers.

[edit]

stdafx.h

stdafx.h is a file, generated by Microsoft Visual Studio IDE wizards, that describes both standard system and project specific include files that are used frequently but hardly ever change.

Compatible compilers (for example, Visual C++ 6.0 and newer) will precompile this file to reduce overall compile times. Visual C++ will not compile anything before the#include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.

The AFX in stdafx.h stands for Application Framework eXtensions. AFX was the original abbreviation for the Microsoft Foundation Classes (MFC). While the name stdafx.h is used by default, projects may specify an alternative name.


看来这个stdafx.h是起了一个标识的作用,不具有通常.h文件的功能。
重点在于:  Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.
这个precompiled header是为了减少编译时由于#include带来的不必要的编译的负担。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值