在Visual Studio 2022版本17.6中的预编译头错误。

huangapple go评论82阅读模式
英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;Project ToolsVersion=&quot;4.0&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;

    &lt;ItemDefinitionGroup&gt;
        &lt;ClCompile&gt;
        &lt;BuildStlModules&gt;false&lt;/BuildStlModules&gt;
        &lt;/ClCompile&gt;
    &lt;/ItemDefinitionGroup&gt;
&lt;/Project&gt;

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)

huangapple
  • 本文由 发表于 2023年5月21日 03:01:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296911.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定