• <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
            數據加載中……

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

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

            今天在改一個舊的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

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

            国产无套内射久久久国产| 久久久噜噜噜久久中文福利| 伊人久久免费视频| 国产成人精品久久亚洲| 色诱久久av| 久久久久亚洲AV成人片| 久久国产视屏| 亚洲人成精品久久久久 | 大蕉久久伊人中文字幕| 欧美亚洲另类久久综合婷婷| 久久99精品国产麻豆宅宅| 久久精品嫩草影院| 精品综合久久久久久98| 办公室久久精品| 久久青青草原精品国产| 亚洲色欲久久久久综合网| 国产成人久久精品区一区二区| 色欲综合久久躁天天躁| 欧美激情精品久久久久| 久久婷婷色综合一区二区| 国产精品成人99久久久久 | 国产精品美女久久久免费| 伊色综合久久之综合久久| 亚洲综合久久综合激情久久| 久久99热这里只有精品国产| 久久婷婷人人澡人人| 色综合久久中文综合网| 国产成人久久AV免费| 国产A三级久久精品| 亚洲国产视频久久| 色欲综合久久躁天天躁| 91精品国产高清久久久久久91| 国产午夜福利精品久久2021| 久久综合九色综合网站| 久久AV无码精品人妻糸列| 久久人妻少妇嫩草AV蜜桃| 四虎国产精品成人免费久久| 香蕉久久久久久狠狠色| 国产成人精品综合久久久久| 伊人色综合久久天天人手人婷| 久久精品一本到99热免费|