Fedor
Fedor

Reputation: 21347

Precompiled header errors in Visual Studio 2022 version 17.6

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 Studio\2022\Community\VC\Tools\MSVC\14.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 Studio\2022\Community\VC\Tools\MSVC\14.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 Studio\2022\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 Studio\2022\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 Studio\2022\Community\VC\Tools\MSVC\14.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?

Upvotes: 12

Views: 2776

Answers (2)

Donpedro
Donpedro

Reputation: 858

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)

Upvotes: 1

head scratcher
head scratcher

Reputation: 166

To fix this problem, change this setting: Project properties > C/C++ > Language > Build ISO C++23 Standard Library Modules > No.

Upvotes: 15

Related Questions