Up and Running with C++ Modules in VS2026 — A Complete Hands-On Guide
Introduction
Modern C++ brought in a genuinely breakthrough feature: modules. They have had some time to mature by now (this thing shipped with C++20), and in demo cases VS's support for modules is already OK. We are also planning to give it a try — gradually introducing modules into some of our toy projects to simplify how the project's dependency handling works.
Why Use Modules
C++ modules (C++20) are a compilation-unit mechanism meant to replace traditional header files. Before, whenever a source file changed, that entire source file had to be recompiled from scratch. Module-based incremental compilation, however, analyzes things down to the binary ABI level. MSVC's modules (yes, they are in practice not very interoperable with other compiler vendors) cache compilation artifacts via the module binary interface / BMI, and this time around the export story is more robust. Module import and export are done with exactly two keywords: import and export.
Prerequisites
VS2022 is no longer up for download these days (at least it is not easy to get hold of), which is exactly why we went with VS2026. To use modules smoothly on VS2026, confirm the following:
- Visual Studio 2026 (or newer) is installed, including the "Desktop development with C++" workload. VS2026 ships with MSVC Build Tools v14.50 (IDE 18.0), with further improvements to modules and language compatibility. So these days there is essentially no burden — no need to separately enable any experimental features; it went mainstream a long time ago.
- C++ standard settings: the project or command line uses
/std:c++20, or more aggressively/std:c++latest(VS2026's MSVC provides more complete support for modules). But don't worry — VS2026 already defaults to the option above, so there is nothing to change; if you are the cautious type, just take one look to make sure
Minimal Runnable Example (Code and Step-by-Step Instructions)
Create a small project vs2026-modules-demo/ with two files:
math.ixx (module interface unit):
export module math;
export int add(int a, int b) {
return a + b;
}
export struct Point { int x, y; };main.cpp (consuming the module):
import std;
import math;
int main()
{
std::print("Add Result: {}", add(1, 2));
Point p{ 1,2 };
std::print("Point p ({}, {})\n", p.x, p.y);
return 0;
}Note: In the MSVC community,
.ixxis the common module interface extension; you can also use.cppmand the like, but the IDE/toolchain may recognize extensions differently by default.
Using Modules in the Visual Studio IDE (VS2026) — Steps
Visual Studio has already handed most of the module build details over to MSBuild/the IDE, so usually all you need to do is add the files to the project:
- Create a new project:
Console App (C++)(with the Desktop development with C++ workload selected). - Add the module files to the project: right-click the project → Add → Existing Item → add
math.ixxandmain.cpp. - Confirm the language settings: right-click the project → Properties → C/C++ → Language → for
C++ Language StandardchooseISO C++20or above (choosingPreviewworks too). At the same time, still under Properties → C/C++ → Language, set the "Build C++23 Standard Library Modules" option to Yes. - Build and run: the IDE automatically scans module sources, generates BMIs, and sets the compilation and linking order correctly; you normally do not need to manually specify
.objfiles. If dependencies between modules get complicated (cross-project), you can use project references or configure Module References in Project Properties.