Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1466675
  • 博文数量: 218
  • 博客积分: 6394
  • 博客等级: 准将
  • 技术积分: 2563
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-08 15:33
个人简介

持之以恒

文章分类

全部博文(218)

文章存档

2013年(8)

2012年(2)

2011年(21)

2010年(55)

2009年(116)

2008年(16)

分类:

2009-12-03 15:39:41

转:http://blog.sina.com.cn/s/blog_48f93b530100fkcg.html
和原文稍微有改动!

今天在VC2005中修改一个工程的文件结构,将"stdafx.cpp"文件挪动了位置,编译时出现C2859错误,具体信息如下:

error C2859: e:\projects\apptest\src\debug\vc80.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header. e:\projects\apptest\src\mainapp.cpp 

error C2859: e:\projects\apptest\src\debug\vc80.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header. e:\projects\apptest\src\mainapp.cpp 4

(这个应该是Make的规则在起作用)按照提示要求,clean编译文件,rebuild工程,还是一样的问题。发现debug文件夹下总是有一个mainapp.pch文件(预编译文件),即使clean也不会删除。将该文件手动删除,rebuild工程,出现C1083错误:

    fatal error C1083: Cannot open precompiled header file: 'Debug\MainApp.pch': No such file or directory e:\projects\apptest\src\mainapp.cpp 

    查看工程设置properties -> Configuration Properties -> C/C++ -> Precompiled Headers,为“Use Precompiled Headers (/Yu)”,所以预编译文件mainapp.pch不会自动生成;改为“Create Precompiled Headers (/Yc)”,rebuild工程,ok。

    但是工程原来的设置“Use Precompiled Headers (/Yu)”是可以编译成功的啊,于是再改回原来的设置,build,出现LNK2001错误:

    error LNK2001: unresolved external symbol "int __cdecl _AfxInitManaged(void)" () mfcs80ud.lib 

    百思不得其解,google上找答案,原来VC对于预编译的设置是这样的:

    1、"stdafx.cpp"文件的预编译选项永远是“Create Precompiled Headers (/Yc)”;

    2、工程的预编译选项一般为“Use Precompiled Headers (/Yu)”。

    可知"stdafx.cpp"文件的预编译选项一般与工程的预编译选项设置是不同的,也就是说每次build工程时,"stdafx.cpp"文件都要生成预编译文件*.pch,而其他cpp文件则直接用这个文件进行编译。于是选中"stdafx.cpp"文件,右键“Properties”,选择 “All Configurations”,将预编译选项设置为“Create Precompiled Headers (/Yc)”,再次rebuild,一切ok。

   回忆引起出错的操作,是从工程中删除"stdafx.cpp"文件后又添加到工程中的。看来VC框架生成的工程会自动将"stdafx.cpp"文件的预编译选项设置好,如果用户手动添加该文件的话,预编译选项将会与工程的选项相同。打开一个以前的MFC工程查看,果然验证了自己的想法。

=================================================================================
VS2005,找不到设置包含头文件目录的地方,属性里没有C++那个选项卡,只有链接器的配置?
原因是工程里面没有CPP的文件。
阅读(1571) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~