我有一个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一样的错误.
多谢.

解决方案 »

  1.   

    把*.pdb, *.pch都删除,然后不要选择Use Precompiled Header,先选择Create Precompiled Header编译一遍,然后再选择Use Precompiled Header
      

  2.   

    这种方法是可以成功的将一个非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也能成立。
      

  3.   

    单独将stdafx.cpp的属性改成:Create Precompiled Header,而整个工程的该项属性设置为Use Precompiled Header。
    这样rebuild的时候就不会报以上错误