• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 40, 文章 - 0, 評論 - 9, 引用 - 0
            數(shù)據(jù)加載中……

            vc的stdafx文件和C1083、C1010錯誤(轉(zhuǎn))

            http://blog.csdn.net/gofishing/archive/2006/04/12/660798.aspx

            今天在改一個舊的vc6工程(為了節(jié)省空間和方便備份,以前收尾時把中間文件都刪了),整理了一下文件,歸了歸類,結(jié)果不知怎么的,工程不能編譯了,編譯 什么文件都出現(xiàn) fatal error C1083: Cannot open precompiled header file: 'Debug/xxx.pch': No such file or directory, 可是我也沒刪什么文件,改程序內(nèi)容,就是把文件挪了挪,看來是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文件。只有新建一個工程,然后把原來的源文件都加過去,要是工程里有很多源文件,進行了很多設(shè)置的話,可就麻煩了。

            于 是,我新建了一個工程就叫test把,看看怎么會出現(xiàn)fatal error C1083的。在新建一個工程后,vc在工程目錄里生成了幾個文件,包括 test.dsp(工程文件)、StdAfx.h、StdAfx.cpp。和主程序源文件test.cpp等。如果你build工程,會在相應(yīng)的編譯目錄 下(一般為debug或release)產(chǎn)生test.pch、vc60.idb、vc60.pdb、StdAfx.obj和源程序的obj、pdb文件 和一個test.exe程序,fatal error C1083就是說沒有這個.pch文件,他也不能產(chǎn)生這個文件。那到底vc是怎么產(chǎn)生這個文件的, 又是作了什么改動使他不能再產(chǎn)生這個文件的呢?我們將debug目錄刪除,然后編譯test.cpp文件,結(jié)果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產(chǎn)生了test.pch,然后再編譯test.cpp的把;再把debug目錄刪了,編譯StdAfx.cpp就ok,看看 debug目錄:test.pch、StdAfx.obj、vc60.idb、vc60.pdb。原來是編譯StdAfx.cpp產(chǎn)生的pch文件,那從 工程里刪除這個文件然后在添加這個文件為什么不行呢?肯定是在在刪除/添加StdAfx.cpp文件過程中,工程文件不一樣了。先關(guān)閉工程,把 test.dsp備份,然后打開工程,刪除StdAfx.cpp文件,在添加,編譯,錯誤C1083,然后關(guān)閉工程(保存工程)。fc比較一下剛才備份的 dsp和現(xiàn)在的工程文件,發(fā)現(xiàn)原來正常的那個工程文件里在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文件是預(yù)編譯頭 (PreCompiled Header),下邊是msdn里關(guān)于PreCompiled Header和/Yc選項的解釋。一直都是用集成編譯環(huán)境的, 先是tc,然后是vc,沒用過make,沒寫過makefile,對編譯、連接這些東西還不是很懂,高手見笑了。這個選項是可以在工程的設(shè)置里設(shè)的,具體 可以看下邊的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

            posted on 2008-09-04 14:17 閱讀(1342) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            婷婷久久久亚洲欧洲日产国码AV | 久久成人18免费网站| 国产精品99久久久久久www| 91久久福利国产成人精品| 久久影院久久香蕉国产线看观看| 欧美激情精品久久久久久久九九九| 亚洲中文字幕无码久久综合网| 69SEX久久精品国产麻豆| 久久亚洲国产精品五月天婷| 7777久久亚洲中文字幕| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久久久波多野结衣高潮| 久久综合九色综合欧美狠狠| 色播久久人人爽人人爽人人片AV| 精品久久一区二区三区| 精品久久久久久久久免费影院| 久久99热精品| 97久久超碰国产精品2021| 18禁黄久久久AAA片| 久久e热在这里只有国产中文精品99 | 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 一本一道久久精品综合| 亚洲日韩中文无码久久| 九九久久精品无码专区| 精品久久一区二区三区| 久久国产精品99国产精| 蜜臀久久99精品久久久久久小说| 久久av免费天堂小草播放| 国产精品免费看久久久香蕉| 久久精品www| 51久久夜色精品国产| 国产91久久精品一区二区| 国内精品久久久久影院日本 | 久久香综合精品久久伊人| 久久一区二区免费播放| 国内精品久久久久久久coent| 久久久久久免费一区二区三区| 久久最近最新中文字幕大全| 久久这里只有精品久久| 嫩草影院久久国产精品| 亚洲国产精品久久久久|