`
mmdev
  • 浏览: 12909594 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

vc的stdafx文件和C1083、C1010错误(.pch: No such file ...)

 
阅读更多

vc的stdafx文件和C1083、C1010错误

今天在改一个旧的vc6工程(为了节省空间和方便备份,以前收尾时把中间文件都删了),整理了一下文件,归了归类,结果不知怎么的,工程不能编译了,编译什么文件都出现fatal error C1083: Cannot open precompiled header file: 'Debug/xxx.pch': No such file or directory,可是我也没删什么文件,改程序内容,就是把文件挪了挪,看来是vc的工程有点问题,只好查查怎么回事。

用vc新建的工程一般都有这两个文件(空工程除外),其实如果不用mfc,这两个根本没用
StdAfx.cpp 就一句#include "stdafx.h"
StdAfx.h 包含了一些头文件,如果没用mfc就一句有用的#include <stdio.h>
要是你把哪个源文件的#include "stdafx.h"这行删除了,或者从其他工程考过来一个文件没有这行的,编译时一律是fatal error C1010: unexpected end of file while looking for precompiled header directive,这时你只要给该文件开头加个#include "stdafx.h"就了事。
这两个文件除了这点之外还有一个问题,就是这两个文件不能从工程里删除,不然你编译任何一个.cpp/.c的文件都会报fatal error C1083: Cannot open precompiled header file: 'Debug/xxx.pch': No such file or directory,你build也不行,vc会给每一个源文件报这样一个错误。

你再把这两个文件加入工程,一样不行,不论你把他们加在哪,怎么编译就是fatal error C1083,找不到.pch文件。只有新建一个工程,然后把原来的源文件都加过去,要是工程里有很多源文件,进行了很多设置的话,可就麻烦了。

于是,我新建了一个工程就叫test把,看看怎么会出现fatal error C1083的。在新建一个工程后,vc在工程目录里生成了几个文件,包括test.dsp(工程文件)、StdAfx.h、StdAfx.cpp。和主程序源文件test.cpp等。如果你build工程,会在相应的编译目录下(一般为debug或release)产生test.pch、vc60.idb、vc60.pdb、StdAfx.obj和源程序的obj、pdb文件和一个test.exe程序,fatal error C1083就是说没有这个.pch文件,他也不能产生这个文件。那到底vc是怎么产生这个文件的,又是作了什么改动使他不能再产生这个文件的呢?我们将debug目录删除,然后编译test.cpp文件,结果j:/test/test.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/test.pch': No such file or directory;不行,我build:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
test.cpp
Linking...
test.exe - 0 error(s), 0 warning(s)

看来是编译StdAfx.cpp产生了test.pch,然后再编译test.cpp的把;再把debug目录删了,编译StdAfx.cpp就ok,看看debug目录:test.pch、StdAfx.obj、vc60.idb、vc60.pdb。原来是编译StdAfx.cpp产生的pch文件,那从工程里删除这个文件然后在添加这个文件为什么不行呢?肯定是在在删除/添加StdAfx.cpp文件过程中,工程文件不一样了。先关闭工程,把test.dsp备份,然后打开工程,删除StdAfx.cpp文件,在添加,编译,错误C1083,然后关闭工程(保存工程)。fc比较一下刚才备份的dsp和现在的工程文件,发现原来正常的那个工程文件里在SOURCE=./StdAfx.cpp之后多这么一行# ADD CPP /Yc"stdafx.h",而删了StdAfx.cpp再添加的工程就没有,其他的就完全一样。

正常的dsp文件包含StdAfx.cpp的这两行是这样的:
SOURCE=./StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File

后记:
vc真是奇怪呀,这行# ADD CPP /Yc"stdafx.h"在新建工程时有,从工程里删除了StdAfx.cpp就没有了,再在工程里加上这个StdAfx.cpp就没有加上。看似删除再添加好像没有动工程,谁知道他来这么一手,艾,要是懂编译懂vc的还好,要是遇上我这样的菜鸟,艾,只有和他奋斗半天才把他搞得稀里糊涂。把他写出来,免得和我一样的菜鸟再费半天劲。

其实这个pch文件是预编译头(PreCompiled Header),下边是msdn里关于PreCompiled Header和/Yc选项的解释。一直都是用集成编译环境的,先是tc,然后是vc,没用过make,没写过makefile,对编译、连接这些东西还不是很懂,高手见笑了。这个选项是可以在工程的设置里设的,具体可以看下边的msdn帮助。

/Yc  (Create Precompiled Header File)
Home | Overview | How Do I | Compiler Options
This option instructs the compiler to create a precompiled header (.PCH) file that represents the state of compilation at a certain point. (To find this option in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click Precompiled Headers in the Category box.)
Command Line Project Settings Description
/Yc Create Precompiled Header File The compiler compiles all code up to the end of the base source file, or to the point in the base file where #pragma hdrstop occurs. 
/Ycfilename Through Header The compiler compiles all code up to and including the .H file specified in the Through Header text box (filename). 

The precompiled code is saved in a file with a name created from the base name of the file specified with the /Yc option and a .PCH extension. You can also use the /Fp option to specify a name for the precompiled header file.
If you use /Ycfilename (Through Header), the compiler compiles all code up to and including the specified file for subsequent use with the /Yu option.
Note  If the options /Ycfilename and /Yufilename occur on the same command line and both reference, or imply, the same file name, /Ycfilename, takes precedence. This feature simplifies the writing of makefiles.
Example
Consider the following code:
#include <afxwin.h>  // Include header for class library
#include "resource.h" // Include resource definitions
#include "myapp.h"  // Include information specific to this app
...
When this code is compiled with the command
CL /YcMYAPP.H PROG.CPP
the compiler saves all the preprocessing for AFXWIN.H, RESOURCE.H, and MYAPP.H in a precompiled header file called MYAPP.PCH.
See Also  Creating Precompiled Header Files

--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

来自:http://www.xici.net/b2463/d2405722.htm

分享到:
评论

相关推荐

    fatal error C1083: 无法打开包括文件:“stdint.h”: No such file or directory。

    fatal error C1083: 无法打开包括文件:“stdint.h”: No such file or directory. stdint.h是c99标准的头文件,vc不支持,所以肯定会提示“No such file or directory”的。使用方法:下载压缩包,解压得到两个.h...

    vc的stdafx文件和C1083、C1010错误

    介绍了产生C1083以及1010错误的一般原因,以及解决之道

    VC++常见错误一览表

    2、fatal error C1083: Cannot open include file: 'R…….h': No such file or directory 不能打开包含文件“R…….h”:没有这样的文件或目录。 3、error C2011: 'C……': 'class' type redefinition 类“C……...

    终于搞懂了,预编译头文件

    &lt;br&gt;结果不能编译了,我靠: &lt;br&gt;fatal error C1083: Cannot open precompiled header file: \'Debug/v13_3.pch\': &lt;br&gt;No such file or directory &lt;br&gt;怎么rebuild all都不行。 &lt;br&gt;上网查了一下,...

    最常见的20种VC++错误

    最常见的20种VC++错误,比如:1、fatal error C1010: ...2、fatal error C1083: Cannot open include file: 'R…….h': No such file or directory 不能打开包含文件“R…….h”:没有这样的文件或目录。。。。

    头文件免费下载

    // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_STDAFX_H__C4B5DA9B_21...

    StdAfx.h头文件下载,编程必备!

    预编译头文件通过编译stdafx.cpp生成,以工程名命名,由于预编译的头文件的后缀是“pch”,所以编译结果文件是projectname.pch。...否则,你将会得到“No such file or directory”这样让你百思不得其解的错误提示。

    算法.cpp : 定义控制台应用程序的入口点。

    #include "stdafx.h" #include #define INFINITE 100000 using namespace std; int MERGE_INVESTIONS(int a[],int p,int q,int r); int COUNT_INVERSIONS(int a[],int p,int r); int main() { int a[5]={5,4,3,2,1...

    VC++最常见的20种编译错误信息

    2、fatal error C1083: Cannot open include file: ''R…….h'': No such file or directory 不能打开包含文件“R…….h”:没有这样的文件或目录。 3、error C2011: ''C……'': ''class'' type redefinition 类...

    stdafx_h头文件

    预编译头文件通过编译stdafx.cpp生成,以工程名命名,由于预编译的头文件的后缀是“pch”,所以编译结果文件是projectname.pch。...否则,你将会得到“No such file or directory”这样让你百思不得其解的错误提示。

    头文件下载

    将此文件&lt;stdafx.h&gt;放在头文件目录中,可解决编译失败问题。编译器通过一个头文件stdafx.h来使用预编译头文件。stdafx.h这个头文件名是可以在project的编译设置里指定的。编译器认为,所有在指令#include "stdafx.h...

    StdAfx.rar_ stdafx.h_stdafx_stdafx.h_stdafx.h 头文件

    StdAfx.h vc++重要的头文件的 要放到vc98/include文件夹里面

    c编译器源代码

    CONSOLE APPLICATION : C_... named C_Minus.pch and a precompiled types file named StdAfx.obj. Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize.

    C++调用java代码的JNI实现

    stdafx.h:vc2005自动生成的,在这个文件中要加入jni相关的头文件如下 jni.h:jdk中自带的头文件,可以在Java\jdk1.5.0_09\include下面找到,它还参考一个jni_md.h jni_md.h:jdk中自带的头文件,可以在Java\jdk...

    vc StdAfx头文件

    VC中的StdAfx头文件 // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_...

    stdafx.h文件

    stdafx.h : 标准系统包含文件的包含文件。  Microsoft C 和 C++ 编译器提供了用于预编译任何 C 或 C++ 代码(包括内联代码)的选项。利用此性能特性,可以编译稳定的代码体,将已编译状态的代码存储在文件中,以及...

    stdafx.h 头文件

    stdafx.h 头文件 很多时候c运行 提示找不到stdafx.h ,

    C语言头文件StdAfx.h

    编译器通过一个头文件stdafx.h来使用预编译头文件。stdafx.h这个头文件名是可以在project的编译设置里指定的。

    Linux中gdb查看core堆栈信息

    VC就根据这个选项把 StdAfx.cpp编译成一个Obj文件和一个PCH文件 。 然后我们再选择一个其它的文件来看看,//其他cpp文件 在这里,Precomplier 选择了 Use ⋯⋯⋯一项,头文件是我们指定创建PCH 文件的stda fx.h 文件...

    raw socket编写的禁止别人扫描自己机器的程序

    CONSOLE APPLICATION : 003 ... named 003.pch and a precompiled types file named StdAfx.obj. Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize.

Global site tag (gtag.js) - Google Analytics