新建一个 test.cpp 文件 ,编译时提示
fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.把 #include "stdafx.h" 加上 即通过编译。然后把 #include "stdafx.h" 这行删掉
把 stdafx.h 中的所有内容 copy 到 test.cpp编译提示错误: fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
我的问题是:1. 为什么 test.cpp 中一定要加上 #include "stdafx.h" ?
2. 为什么 #include "stdafx.h" 不能用 "stdafx.h" 文件中的内容代替?谢谢。
fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.把 #include "stdafx.h" 加上 即通过编译。然后把 #include "stdafx.h" 这行删掉
把 stdafx.h 中的所有内容 copy 到 test.cpp编译提示错误: fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
我的问题是:1. 为什么 test.cpp 中一定要加上 #include "stdafx.h" ?
2. 为什么 #include "stdafx.h" 不能用 "stdafx.h" 文件中的内容代替?谢谢。
#include "stdafx.h" 1. 是 VC 的一个默认头文件,一定要包含的啊
2. 实现和申明不一样,这是 c++ 的规则
Project Setting->General->Not using precompiled headers
在Project setting 中C/C++的Project Options中有 /Yu"stdafx.h",
编译从预处理开始.
这就是这样!
to DentistryDoctor(牙科医生) :
在哪里设置的?/* 这是因为在编译选项中设置了通过stdafx.中创建和使用PCH.(C++下的预编译头),如果编译选项中设置此头文件为其它文件,则需要包含你所设置的文件。 */to hzhxxx(程序方程) :
1 . 一定要包含?
2 . 实现和声明不一样,那就要包含 stdafx.h ? 好像没什么必然联系啊! ?
/*1. 是 VC 的一个默认头文件,一定要包含的啊
2. 实现和申明不一样,这是 c++ 的规则*/
VC6.0等一下呀,应该是在编译选项中的C/C++页下吧
#include <afxwin.h> // MFC core and standard components
我想问一下:设置这个东西有什么好处?
这时因为该模块没有包括预编译头文件“stdafx.h”的缘故。
VC用一个stdafx.cpp包含头文件stdafx.h,然后在stdafx.h里包含大部分系统头文件,这
样编译时VC就通过编译stdafx.cpp把大部分系统头文件预编译进来了,在Debug目录下有
一个很大的文件*.pch,这里就存储了预编译信息。
根据这个原理,如果这个pch损坏了或被删除了,系统重新编译时就会抱怨“cannot open
precompiled header file debug/*.pch”。这时怎么解决这个问题呢,打开Project-》
Setting对话框选C++页,将Category下拉式列表框选中Precompiled Headers,最简单的
办法就是选中第一个选项“Not using....",这样就根本不用预编译头也不去寻找pch文件,
就不会出错了,但是这样做的后果是每次编译、连接都化更多的时间。
也可以选第二个选项”Automatic ...",然后在“Through header”力填上stdafx.h,这样
如果没有pch文件系统会自动生成一个pch,如果有的话就使用这个pch,这个选项是比较“
智能”的。
第三个选项是强行创建一个pch文件,第四个选项是直接使用pch文件。当然“Through
headers”里都填stdafx.h了。
附赠一个小花招:
如果编译、连接时总出稀奇古怪的错误或者调试时单步执行走的代码都不符合自己的想法
因为你连接时一般都选用的incremental linking,每次增加一点,有可能把以前的错误
的东西留在连接出来的可执行文件里了。不如彻底重新编译、连接一遍。
StdAfx.h是每个MFC程序的类中必须包括的文件,它一般由AppWizard自动生成,包括编译MFC类所必须的定义。
StdAfx.h是每个MFC程序的类中必须包括的文件,它一般由AppWizard自动生成,包括编译MFC类所必须的定义。