请问如何让不是precompile的工程变成precompile

donkey301 2008-12-01 10:03:18
我有一个project原来不是precomile的,现在我想要变成precompile,我做了如下的尝试,但没有成功,请问什么原因?
1。 增加stdafx.h和stdafx.cpp两个文件
2。 让project中所有的工程都#include "stdafx.h"
3. project property中选择Use precompile

-------------尝试 1------------------
rebuild project 得到错误如下:
1>------ Rebuild All started: Project: test6, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test6', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>e:\yanwei\work\cpp\testprecompile\test6\source\stdafx.cpp(5) : error C2859: e:\yanwei\work\cpp\testprecompile\test6\test6\debug\vc80.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
1>e:\yanwei\work\cpp\testprecompile\test6\source\stdafx.cpp(5) : error C2859: e:\yanwei\work\cpp\testprecompile\test6\test6\debug\vc80.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.
1>test6.cpp
1>e:\yanwei\work\cpp\testprecompile\test6\source\test6.cpp(4) : error C2859: e:\yanwei\work\cpp\testprecompile\test6\test6\debug\vc80.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
1>e:\yanwei\work\cpp\testprecompile\test6\source\test6.cpp(4) : error C2859: e:\yanwei\work\cpp\testprecompile\test6\test6\debug\vc80.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.
1>Generating Code...
1>Build log was saved at "file://e:\yanwei\work\Cpp\testprecompile\test6\test6\Debug\BuildLog.htm"
1>test6 - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

就算我先编译stdafx.cpp也是上面的错误。

-------------尝试 2------------------
把debug目录删除,rebuild
1>------ Rebuild All started: Project: test6, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test6', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>e:\yanwei\work\cpp\testprecompile\test6\source\stdafx.cpp(5) : fatal error C1083: Cannot open precompiled header file: 'Debug\test6.pch': No such file or directory
1>test6.cpp
1>e:\yanwei\work\cpp\testprecompile\test6\source\test6.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug\test6.pch': No such file or directory
1>Generating Code...
1>Build log was saved at "file://e:\yanwei\work\Cpp\testprecompile\test6\test6\Debug\BuildLog.htm"
1>test6 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

我把use precompile改为create precompile,rebuild这会倒是编译通过了,但再次改回use precompile还是和尝试1一样的错误.
多谢.
...全文
380 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wezhousheng 2009-03-17
单独将stdafx.cpp的属性改成:Create Precompiled Header,而整个工程的该项属性设置为Use Precompiled Header。
这样rebuild的时候就不会报以上错误
回复
程序员刘帅 2008-12-01
把*.pdb, *.pch都删除,然后不要选择Use Precompiled Header,先选择Create Precompiled Header编译一遍,然后再选择Use Precompiled Header
回复
donkey301 2008-12-01
这种方法是可以成功的将一个非precompile的project编程precompile的,但还是与一开始创建project的时候就precompile不一样,
在创建时就precompile的project在rebuild时依然不报错,而且从编译顺序来看就是先编译stdafx.cpp
譬如:
1>------ Rebuild All started: Project: test7, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test7', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>test7.cpp
1>Compiling manifest to resources...
1>Linking...
1>LINK : E:\yanwei\work\Cpp\testprecompile\test7\Debug\test7.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Build log was saved at "file://e:\yanwei\work\Cpp\testprecompile\test7\test7\Debug\BuildLog.htm"
1>test7 - 0 error(s), 0 warning(s)

先编译的stdafx.cpp再编译test7.cpp,所以没报错。

但如果创建时选not use precompile,后来又加了stdafx.cpp/h变成use precompile时,如果rebuild就会报错:
1>------ Rebuild All started: Project: test8, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test8', configuration 'Debug|Win32'
1>Compiling...
1>test8.cpp
1>e:\yanwei\work\cpp\testprecompile\test8\test8\test8.cpp(4) : error C2859: e:\yanwei\work\cpp\testprecompile\test8\test8\debug\vc80.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
1>e:\yanwei\work\cpp\testprecompile\test8\test8\test8.cpp(4) : error C2859: e:\yanwei\work\cpp\testprecompile\test8\test8\debug\vc80.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.
1>stdafx.cpp
1>e:\yanwei\work\cpp\testprecompile\test8\test8\stdafx.cpp(5) : error C2859: e:\yanwei\work\cpp\testprecompile\test8\test8\debug\vc80.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
1>e:\yanwei\work\cpp\testprecompile\test8\test8\stdafx.cpp(5) : error C2859: e:\yanwei\work\cpp\testprecompile\test8\test8\debug\vc80.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.
1>Generating Code...
1>Build log was saved at "file://e:\yanwei\work\Cpp\testprecompile\test8\test8\Debug\BuildLog.htm"
1>test8 - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
而且可以看出这会先编译test8.cpp,所以找不到.pch文件。
请问怎么才能让test8,rebuild也能成立。
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2008-12-01 10:03
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……