1. 程式人生 > >關於VC編譯錯誤fatal error C1083的解決辦法

關於VC編譯錯誤fatal error C1083的解決辦法

錯誤總是不斷的,經驗是累積的。

C1083: Cannot open precompiled header file: 'Debug/<Project-Name>.pch': No such file or directory

This error results from a missing file - the compiled version of StdAfx.cpp. Visual C++ does a poor job of keeping track of this file and frequently "forgets" how to build it. This problem often occurs after restoring a saved workspace from diskette without the Debug directory. To fix the error select StdAfx.cpp from the workspace file list them choose Compile from the Build menu.  If that doesn't work the go to Project -> Settings, select the C/C++ tab, and click the radio button labeled Create Precompiled Headers. 

Unexpected end while looking for precompiled header
這時因為該模組沒有包括預編譯標頭檔案“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了。