如何解决:fatal error C1010: unexpected end of file while looking for precompiled header directive
我也遇到了这个问题,但是被我解决了.解决的方案如下:
我有一个工程如下含有如下文件:
Source Files
dllExam1.cpp //TheApp 对象在这个文件中
MyComDlg.cpp //我自己的函数实现在这里
StdAfx.cpp //
Header Files
dllExam1.h //WinApp类的头文件
MyComDlg.h //我自己函数的头文件
StdAfx.h
此时编译的时候有错误,且错误是发生在MyComDlg.cpp中.提示如下:
fatal error C1010: unexpected end of file while looking for precompiled
header directive
查阅Msdn得到的结果:
This error can be caused by specifying an incorrect file as a header file, or
by specifying an include file with the /Yu (Use Precompiled Header) command
line option that is not listed in the source file as an include file.
.,☆要在你(自己)的文件中包含这个(被要求预编译的)头文件☆既在如上工程中的文件MyComDlg.cpp中包含"stdafx.h".这样再此编译问题解决.为什么"stdafx.h"要包含
在你的文件中呢?因为.在Project->Setting->Compile中"stdafx.h"被设置为/Yu"stdafx.h"这
就是说"stdafx.h"这个文件被要求了预编
.////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
使用visual C++时,总是包含了头文件stdafx.h,却不知道是干什么用的. 今天查找了相关资料,解释如下:
当我们使用AppWizard来自动生成某些项目的时候,系统会自动把所需要include的头文件在stdafx.h中先include一下,这样,我们只需要直接include这个stdafx.h文件即可.因为同一个项目中的不同源文件CPP都包含相同的include文件,这样,为每个.CPP文件都重复include这些文件就显得很傻了。
具体在stdafx.h中需要include什么头文件,取决于用户在AppWizard中的选择.
比如:
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
......
等等,这样,就方便多了.所以,stdafx.h是自动生成的.这就使得用户在开发中不必在每一个cpp文件中都烦琐的include头文件了,而且,维护起来也方便.
在生成stdafx.h头文件的同时,也生成了stdafx.cpp源文件,该源文件只包含#include "stdafx.h"语句,这是在编译过程中第一个被编译的文件,编译的结果保存在一个名为stdafx.pch的文件里。 (扩展名pch表示预编译头文件pre-compiled header。)当Visual C++编译随后的每个.cpp文件时,它阅读并使用它刚生成的.pch文件。 Visual C++不再分析Windows include文件,除非用户又编缉了stdafx.cpp或stdafx.h。
所谓头文件预编译,就是把一个工程(Project)中使用的一些MFC标准头文件(如Windows.H、Afxwin.H)预先编译,以后该工程编译时,不再编译这部分头文件,仅仅使用预编译的结果。这样可以加快编译速度,节省时间。
预编译头文件通过编译stdafx.cpp生成,以工程名命名,由于预编译的头文件的后缀是“pch”,所以编译结果文件是projectname.pch。
编译器通过一个头文件stdafx.h来使用预编译头文件。stdafx.h这个头文件名是可以在project的编译设置里指定的。编译器认为,所有在指令#include "stdafx.h"前的代码都是预编译的,它跳过#include "stdafx. h"指令,使用projectname.pch编译这条指令之后的所有代码。
因此,所有的CPP实现文件第一条语句都是:#include "stdafx.h"。
当使用visual C++时,总是包含了头文件stdafx.h,却不知道是干什么用的. 呵呵,今天查找了相关资料,解释如下: 当我们使用AppWizard来自动生成某些项目的时候,系统会自动把所需要include的头文件在stdafx.h中先include一下,这样,我们只需要直接include这个stdafx.h文件即可.因为同一个项目中的不同源文件CPP都包含相同的include文件,这样,为每个.CPP文件都重复include这些文件就显得很傻了。具体在stdafx.h中需要include什么头文件,取决于用户在AppWizard中的选择. 比如: #include <afxwin.h> // MFC core and standard components#include <afxext.h> // MFC extensions#include <afxole.h> // MFC OLE classes#include <afxodlgs.h> // MFC OLE dialog classes#includ
1217

被折叠的 条评论
为什么被折叠?



