Skip to content

Conversation

LiangHuDream
Copy link
Contributor

[fix] error: module file CMakeFiles/__cmake_cxx23.dir/std.pcm cannot be loaded due to a configuration mismatch with the current compilation #4279
What I changed

Edited CMakeLists.txt in the add_module_library logic:
Compute a std_flag that honors CMAKE_CXX_EXTENSIONS:
If CMAKE_CXX_EXTENSIONS is ON, use -std=gnu++.
Otherwise use -std=c++.
Use ${std_flag} when invoking the compiler to precompile modules:
The precompile command previously used -std=c++ unconditionally; now it uses ${std_flag}.
Use ${std_flag} (and the same include dirs) when compiling the .o from the .pcm to ensure a consistent compile configuration.

Why this helps

The "configuration mismatch" (PCM/PCH load failure) is typically caused by the PCM being produced with a different -std variant (e.g., -std=gnu++23) than the compile unit loading it (e.g., -std=c++23). On Clang the difference between gnu++ and c++ influences whether GNU extensions are enabled; that triggers the "GNU extensions was enabled in PCH file but is currently disabled" diagnostic.
Making the precompile and compile use the same -std avoids that mismatch.
The errors showing that types from std (enable_if, conditional, etc.) are missing are consistent with the compiler being in a different configuration or precompiled header context (modules/PCH broken), so fixing the PCM config mismatch should eliminate those follow-on errors.

@vitaut
Copy link
Contributor

vitaut commented Oct 17, 2025

This looks similar to #4580. In the future please update the PR instead of closing and creating a new one.

@LiangHuDream
Copy link
Contributor Author

This looks similar to #4580. In the future please update the PR instead of closing and creating a new one.

OK, thank you for your suggestion.

@vitaut
Copy link
Contributor

vitaut commented Oct 18, 2025

Could you provide an example demonstrating the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants