fatal error C1047: The object or library file "..."was created with an older compiler than other obj

本文详细介绍了如何解决在使用VS2005进行代码编译时,在发布模式下遇到的问题。通过安装SP1升级包,可以彻底解决此错误。此外,文章还推荐了升级到更高版本的Visual Studio作为替代方案。

Debug下编译正常生成,切换到Release就报这个错误。


昨天用VS2005变异时遇到的这个问题,网上搜了一大堆,试了很多不见效。微软这货真是坑爹!


终极解决方法:安装SP1升级包,去搜索:sp1-KB926601-X86-ENU吧。(我用的英文版VS2005,所以这里是英文版的),网上的其他的解决方法都是扯淡,浪费时间。


还有种方法:升级VS,建议使用VS2008及以上版本。

Microsoft Windows [版本 10.0.22631.5335] (c) Microsoft Corporation。保留所有权利。 C:\Users\dell>make --version GNU Make 4.1 Built for x86_64-pc-mingw32 Copyright (C) 1988-2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. C:\Users\dell>cmake --version cmake version 3.27.4 CMake suite maintained and supported by Kitware (kitware.com/cmake). C:\Users\dell>gcc --version gcc (Rev3, Built by MSYS2 project) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. C:\Users\dell>arm-linux-gnueabihf-gcc --version arm-linux-gnueabihf-gcc (Linaro GCC 4.9-2017.01) 4.9.4 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. C:\Users\dell>cd /d D:\20241207\KPC_PEPTXDLRI_Windos\build D:\20241207\KPC_PEPTXDLRI_Windos\build>cmake .. -G "MinGW Makefiles" CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- The C compiler identification is GNU 13.2.0 -- The CXX compiler identification is GNU 13.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: D:/VS CODE anzhuangweizhi/ucrt64/bin/cc.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: D:/VS CODE anzhuangweizhi/ucrt64/bin/c++.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Git version is main: -- Configuring done (9.3s) -- Generating done (0.1s) -- Build files have been written to: D:/20241207/KPC_PEPTXDLRI_Windos/build D:\20241207\KPC_PEPTXDLRI_Windos\build>mingw32-make [ 2%] Building CXX object app_PEPTXDLRI/CMakeFiles/PEPTXDLRI_APP.dir/PEPTXDLRI_console.cpp.obj In file included from D:\20241207\KPC_PEPTXDLRI_Windos\app_PEPTXDLRI\PEPTXDLRI_console.cpp:11: D:/20241207/KPC_PEPTXDLRI_Windos/app_PEPTXDLRI/hvac_if/logic_ptu.h:14:10: fatal error: arpa/inet.h: No such file or directory 14 | #include <arpa/inet.h> | ^~~~~~~~~~~~~ compilation terminated. mingw32-make[2]: *** [app_PEPTXDLRI\CMakeFiles\PEPTXDLRI_APP.dir\build.make:76: app_PEPTXDLRI/CMakeFiles/PEPTXDLRI_APP.dir/PEPTXDLRI_console.cpp.obj] Error 1 mingw32-make[1]: *** [CMakeFiles\Makefile2:117: app_PEPTXDLRI/CMakeFiles/PEPTXDLRI_APP.dir/all] Error 2 mingw32-make: *** [Makefile:90: all] Error 2 D:\20241207\KPC_PEPTXDLRI_Windos\build>
06-26
### 编译错误 C1853 的解决方法 编译错误 `fatal error C1853: 'Release/DesenPrinter.pch' is not a precompiled header file created with this compiler` 通常发生在使用预编译头文件(PCH)时,编译器检测到指定的 `.pch` 文件不是由当前编译器生成的,或者与当前编译环境不兼容。以下是解决此问题的几种方法: #### 1. 修改预编译头文件设置 在项目设置中禁用预编译头文件,或者重新配置预编译头文件的使用方式。具体操作如下: - 打开项目设置(Project Settings),进入 **C/C++** 选项卡。 - 在 **Category** 下拉菜单中选择 **Precompiled Headers**。 - 将选项从 **Use precompiled header file (.pch)** 改为 **Not using precompiled headers**。 - 确认更改后重新编译项目。 如果更改后仍然报错,可以尝试将其改回使用预编译头文件,并选择 **Rebuild All** 重新构建整个项目 [^1]。 #### 2. 清除并重新构建项目 有时,旧的编译文件可能会导致冲突。可以尝试清除项目并重新构建: - 在菜单栏中选择 **Build > Clean**(或 **组建 > 清除**)。 - 然后选择 **Build > Rebuild All**(或 **组建 > 全部重建**)。 此方法可以清除所有中间文件并重新生成 `.pch` 文件,从而解决因文件不一致导致的错误 [^2]。 #### 3. 删除 Debug 或 Release 文件夹中的内容 有时,`.pch` 文件可能损坏或与当前编译器不兼容。可以尝试手动删除 Debug 或 Release 文件夹中的文件: - 删除 Debug 或 Release 文件夹中的 `.pch` 文件及其他临时文件。 - 如果某些文件无法删除,可以尝试关闭项目或重启开发环境后再删除。 - 删除完成后,重新编译项目或执行 **Rebuild All** [^3]。 #### 4. 配置预编译头文件的自动使用 如果希望继续使用预编译头文件,可以配置编译器以自动处理预编译头文件: - 在项目设置中,进入 **C/C++ > Precompiled Headers**。 - 选择 **Automatic use of precompiled headers**。 - 在 **Through header** 字段中输入标准头文件名称,例如 `stdafx.h`。 此配置将允许编译器自动管理 `.pch` 文件的生成和使用 [^4]。 #### 5. 检查项目设置一致性 确保项目中所有文件的预编译头文件设置一致。如果某些文件启用了预编译头文件,而其他文件未启用,可能会导致编译错误。可以通过以下方式检查: - 对每个源文件进行右键点击,选择 **Settings**。 - 进入 **C/C++** 选项卡,确保预编译头文件设置统一 [^5]。 --- ### 示例代码:配置预编译头文件 以下是一个简单的示例,展示如何在项目中启用预编译头文件: ```cpp // stdafx.h #pragma once #include <iostream> #include <vector> #include <string> ``` ```cpp // stdafx.cpp #include "stdafx.h" ``` 在项目设置中,将 `stdafx.h` 配置为预编译头文件,并确保所有源文件都包含 `#include "stdafx.h"`。 --- ### 总结 编译错误 `C1853` 通常与预编译头文件的配置或状态有关。通过调整项目设置、清除旧文件、重新构建项目或配置预编译头文件,可以有效解决此问题。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值