关于VC8中的“fatal error C1083”的故事

来源:互联网 发布:sci数据库是指 编辑:程序博客网 时间:2024/06/05 00:55

如果没有编译stdafx.cpp就不会生成pch,自然会报如下错误:

fatal error C1083: Cannot open precompiled header file: 'Debug/xxx.pch': No such file or directory;

 

但是另人郁闷的是手动编译stdafx.cpp也报上面那个错,这是为啥呢?

 

搞成这样很有可能是您把stdafx.cpp从解决方案中删除、移动过,之后既使再添加也不好使了。

 

其实,这个问题源于项目的vcproj文件。

原来在最初时,vcproj中的stdafx.cpp是这样描述的:

            <File
                RelativePath="./stdafx.cpp"
                >

                <FileConfiguration
                    Name="Debug|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="1"
                    />
                </FileConfiguration>
                <FileConfiguration
                    Name="Release|Win32"
                    >
                    <Tool
                        Name="VCCLCompilerTool"
                        UsePrecompiledHeader="1"
                    />
                </FileConfiguration>

            </File>

但当删除、移动Stdafx.cpp后,红色的这段就没了。也就是说stdafx.cpp与pch的关联没有了,

stdafx.cpp成了一个普通的cpp文件,所以在编译它时也会报那个错。

要解决这个问题很简单,直接修改vcproj文件,在stdafx.cpp项下加上红色部分就OK了。

 

最后补充一下:这个万恶的Bug是VC系列的一贯传统,早在VC6时就开始代代相传了,不知道VC9里还是否有……

原创粉丝点击