编译时出现fatal error C1853: "debug/xxx.pch" is not a precomplied header file with......错误的原因及解决办法(转)
来源:互联网 发布:电子数据库 编辑:程序博客网 时间:2024/05/22 07:28
错误原因:
该错误是因为当项目中混合了 .cpp 和 .c 文件时,编译器会对它们采取不同的编译方式(主要是因为对函数声明的处理方式不同),因而不能共用一个预编译头文件。
在 VC++ 中,默认的预编译头文件是针对 C++ 的 (stdafx.h 和 stdafx.cpp),当然也可以创建针对 C 的预编译头。有趣的是,在旧版的 VC++ 中,这个错误的提示很具有误导性:fatal error C1853: 'xxx.pch' is not a precompiled header file created with this compiler. 常常让人摸不着头脑。应该说,在新版中的这个提示是有所改进的。不过在网上搜索一番,对这个问题往往都是建议对整个项目取消预编译头的设置。这显然不是一个好的解决方案。对于一个比较大的工程来说,使用预编译头可以使总的编译时间大大减少。因而保留预编译头的设置才是比较好的解决方案。搜索 MSDN,针对不同的情况,可以有不同的解决方案:
方案1:适用于绝大多数文件是 .cpp 或绝大多数文件是.c的情况。在这种情况下,将少数的不同类文件设为不使用预编译头是比较平衡的做法,方法是:对于 VC++6.0,在 FileView 里对要取消预编译头的 .c (或 .cpp) 文件点右键,选择 settings,在弹出的对话框右边选择 category 为 precompiled headers,再设置选项为 not using ...;对于 VS2005,则在 solution explorer 中对相应文件点右键选择 properties,在 precompiled headers 项下设置 not using... 即可。如果需要设置多个文件,则可以按住 Ctrl 键再同时选中这些文件并设置。
方案2:如果受影响的文件比较多,则把它们都设置禁止预编译头的话仍然会使项目总体的编译速度大大降低,得不偿失。这时考虑可以为这组文件建立专用的预编译头。在 VC++ 极早期版本(1.5及以前版本)中是支持单个工程中建立分别针对 .c 和 .cpp 的预编译头的,但之后的版本中只支持单独的预编译头。在这种情况下,我们可以在workspace(或 solution)中建立一个新的静态链接库 (Static Library) 工程,将所有的 .c 文件独立出来加入到该工程中单独编译,这样就可以在该静态链接库中针对 .c 文件创建预编译头。但是这样做在一定程度上需要被独立出来的代码在逻辑上是属于同一模块中的,这样才便于维护。不过从设计的角度来说,这个要求一般是满足的,否则就应考虑下项目的总体设计了:P 最后别忘了设置原项目的依赖项 (dependency) 为独立出来的这个静态库项目。
该错误是因为当项目中混合了 .cpp 和 .c 文件时,编译器会对它们采取不同的编译方式(主要是因为对函数声明的处理方式不同),因而不能共用一个预编译头文件。
在 VC++ 中,默认的预编译头文件是针对 C++ 的 (stdafx.h 和 stdafx.cpp),当然也可以创建针对 C 的预编译头。有趣的是,在旧版的 VC++ 中,这个错误的提示很具有误导性:fatal error C1853: 'xxx.pch' is not a precompiled header file created with this compiler. 常常让人摸不着头脑。应该说,在新版中的这个提示是有所改进的。不过在网上搜索一番,对这个问题往往都是建议对整个项目取消预编译头的设置。这显然不是一个好的解决方案。对于一个比较大的工程来说,使用预编译头可以使总的编译时间大大减少。因而保留预编译头的设置才是比较好的解决方案。搜索 MSDN,针对不同的情况,可以有不同的解决方案:
方案1:适用于绝大多数文件是 .cpp 或绝大多数文件是.c的情况。在这种情况下,将少数的不同类文件设为不使用预编译头是比较平衡的做法,方法是:对于 VC++6.0,在 FileView 里对要取消预编译头的 .c (或 .cpp) 文件点右键,选择 settings,在弹出的对话框右边选择 category 为 precompiled headers,再设置选项为 not using ...;对于 VS2005,则在 solution explorer 中对相应文件点右键选择 properties,在 precompiled headers 项下设置 not using... 即可。如果需要设置多个文件,则可以按住 Ctrl 键再同时选中这些文件并设置。
方案2:如果受影响的文件比较多,则把它们都设置禁止预编译头的话仍然会使项目总体的编译速度大大降低,得不偿失。这时考虑可以为这组文件建立专用的预编译头。在 VC++ 极早期版本(1.5及以前版本)中是支持单个工程中建立分别针对 .c 和 .cpp 的预编译头的,但之后的版本中只支持单独的预编译头。在这种情况下,我们可以在workspace(或 solution)中建立一个新的静态链接库 (Static Library) 工程,将所有的 .c 文件独立出来加入到该工程中单独编译,这样就可以在该静态链接库中针对 .c 文件创建预编译头。但是这样做在一定程度上需要被独立出来的代码在逻辑上是属于同一模块中的,这样才便于维护。不过从设计的角度来说,这个要求一般是满足的,否则就应考虑下项目的总体设计了:P 最后别忘了设置原项目的依赖项 (dependency) 为独立出来的这个静态库项目。
0 0
- 编译时出现fatal error C1853: "debug/xxx.pch" is not a precomplied header file with......错误的原因及解决办法(转)
- fatal error C1853: 'Debug/***.pch' is not a precompiled header file created with this compiler
- fatal error C1853: 'Debug/***.pch' is not a precompiled header file created with this c
- fatal error C1853: 'Debug/***.pch' is not a precompiled header file created with this compiler
- fatal error C1853: 'Debug/License.pch' is not a precompiled header file created with this compiler
- 关于fatal error C1853: 'Debug/TrafficDet.pch' is not a precompiled header file created with this compiler
- 关于fatal error C1853: 'Debug/TrafficDet.pch' is not a precompiled header file created with this compi
- [纠错]fatal error C1853: 'Debug/Park.pch' is not a precompiled header file created
- fatal error C1853: '*.pch' is not a precompiled header file created with this compiler
- fatal error C1853: 'Debug\***.pch' precompiled header file is from a previous version of the compil
- vc 出现“fatal error C1085: Cannot write precompiled header file: 'Debug/xxx.pch': The parameter is incorrect“的错误的解决办法
- error C1853: 'Debug\xxx.pch' precompiled header file is from a previous version of the compiler
- VC6.0 fatal error C1853: 'Debug/xx.pch' is not a precompiled header
- \'Debug/XXX.pch\' is not a precompiled header file created with this compiler Error
- fatal error C1853: 'Debug\test.pch' precompiled header file is from a previous version of the compil
- fatal error C1853: 'Debug\test.pch' precompiled header file is from a previous version of the compil
- 20160724 fatal error C1853: 'Debug\test.pch' precompiled header file is from a previous version of t
- atal error C1853: 'Debug\xxx.pch' precompiled header file is from a previous version of the compiler
- LeetCode Binary Tree Postorder Traversal
- 黑马程序员_Java_多线程
- ZOJ - 3809 The Himalayas 暴力
- JQuery获取子孩子和兄弟元素的方法
- 日经社説 20150308 何が患者連続死を招いたか
- 编译时出现fatal error C1853: "debug/xxx.pch" is not a precomplied header file with......错误的原因及解决办法(转)
- 社説 20150308 福島の避難住民 「帰還」見据えた支援の強化を
- .net学习第五天
- C++11中的final关键词
- java.sql.Types,数据库字段类型,java数据类型的对应关系
- android中比较两张图片的相似度
- Struts2拦截器(Interceptor)
- 社説 20150308 米VSイスラエル 中東安定へ亀裂の修復を図れ
- SpringMVC Controller内部跳转如何被拦截器拦截