C++20 Modules
Purpose
Guide agents through authoring, building, and debugging C++20 modules: named modules vs header units, module partitions, CMake integration, compiler-specific flags, and interoperability with legacy headers.
Triggers
- "How do I write a C++20 module?"
- "How do I import a module in CMake?"
- "What's the difference between a named module and a header unit?"
- "My module gives 'cannot find module' errors"
- "How do I use C++20 modules with Clang?"
- "How do I migrate from headers to modules?"
Workflow
1. Module concepts overview
Named modules are the primary target. Header units are a bridge for legacy code. Avoid Global Module Fragment unless required for macro access.
2. Named module — minimal example
3. Module partitions
4. Header units — bridging legacy headers
Header units do NOT provide macros to importers. For macro access, use the Global Module Fragment:
5. Building with Clang
6. Building with GCC
7. CMake integration (CMake ≥3.28)
For CMake 3.25–3.27 (experimental):
8. Common errors
9. Interop with legacy headers
For CMake module support details, see references/modules-cmake-support.md [blocked].
Related skills
- Use
skills/build-systems/build-accelerationfor PCH as a modules alternative - Use
skills/compilers/gccorskills/compilers/clangfor compiler-specific module flags - Use
skills/build-systems/cmakefor CMake project configuration


