英文:
Precompiled header errors in Visual Studio 2022 version 17.6
问题
After updating to Visual Studio 2022 version 17.6, I encountered compilation errors related to the precompiled header MRPch.h
. These errors occurred when including std.compat.ixx
and std.ixx
in my C++ project. Removing the forced include led to a different error about unexpected end of file while looking for the precompiled header. The issue seems to be related to the /std:c++latest
command-line option enabling the latest language features. I checked the Visual Studio 2022 version 17.6 Release Notes but found no information about precompiled headers. Are they no longer compatible with the latest C++ standard?
英文:
I have a Visual Studio C++ project, and after updating Visual Studio 2022 recently from version 17.5 to version 17.6, the compilation stops in the very beginning with the error:
1>------ Rebuild All started: Project: MRPch, Configuration: Debug x64 ------
1>Scanning sources for module dependencies...
1>std.compat.ixx
1>std.ixx
1>C:\Program Files\Microsoft Visual Studio22\Community\VC\Tools\MSVC.36.32532\modules\std.compat.ixx : fatal error C1083: Cannot open include file: 'MRPch.h': No such file or directory
1>C:\Program Files\Microsoft Visual Studio22\Community\VC\Tools\MSVC.36.32532\modules\std.ixx : fatal error C1083: Cannot open include file: 'MRPch.h': No such file or directory
1>C:\Program Files\Microsoft Visual Studio22\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(486,5): warning MSB8074: Cannot read Module Dependencies file C:\Work\MeshInspector\source\TempOutput\MRPch\x64\Debug\std.ixx.module.json: Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''. The build order might be incorrect.
1>C:\Program Files\Microsoft Visual Studio22\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(486,5): warning MSB8074: Cannot read Module Dependencies file C:\Work\MeshInspector\source\TempOutput\MRPch\x64\Debug\std.compat.ixx.module.json: Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''. The build order might be incorrect.
As far as I can see, it is somehow related to the precompiled header MRPch.h
, which is forcedly included in all source files via the compiler option /FI"MRPch.h"
.
If I remove forced include, then the error changes to
C:\Program Files\Microsoft Visual Studio22\Community\VC\Tools\MSVC.36.32532\modules\std.ixx(147,1): fatal error C1010: unexpected end of file while looking for precompiled header.
There are neither std.compat.ixx
nor std.ixx
in my project, but I found that the error is somehow related to /std:c++latest
command-line option, which enables the latest language features.
I looked at Visual Studio 2022 version 17.6 Release Notes, but did not see anything related to precompiled headers there. Are they no longer compatible with the latest C++ standard?
答案1
得分: 14
要解决此问题,请更改此设置:项目属性 > C/C++ > 语言 > 构建ISO C++23标准库模块 > 否。
英文:
To fix this problem, change this setting: Project properties > C/C++ > Language > Build ISO C++23 Standard Library Modules > No.
答案2
得分: 1
我知道原始问题中没有提到CMake,但当我搜索此问题时,它是最早的结果之一,因此我将在这里提供CMake项目的解决方案,也许对其他人有用。
创建一个具有以下内容的属性表(*.props文件):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<BuildStlModules>false</BuildStlModules>
</ClCompile>
</ItemDefinitionGroup>
</Project>
将属性表添加到使用PCHs的目标中,例如:
SET_PROPERTY(TARGET target_name PROPERTY VS_USER_PROPS path_to_props_file.props)
这是CMake项目的解决方案,希望对其他人有所帮助。
英文:
I know there was no mention of CMake in the original question, but it was one of the first results when I searched for this problem, so I'll leave the solution for CMake projects here, maybe it will be useful for others.
Create a Property Sheet (*.props file) with the following content:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<BuildStlModules>false</BuildStlModules>
</ClCompile>
</ItemDefinitionGroup>
</Project>
Add the property sheet to your targets using PCHs, e.g.:
SET_PROPERTY(TARGET target_name PROPERTY VS_USER_PROPS path_to_props_file.props)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论