Visual Studio 2015 Update 1 shipped with experimental support for a module system for C++. You can learn about it from this talk given by Gabriel Dos Reis at CppCon. Creating and consuming modules is very simple, but getting started with the compiler is not that obvious. At least it wasn’t very obvious to me, so here’s a quick introduction to get you started.

Start by creating an interface source file:

You can use an extension other than .ixx but then you need to tell the compiler that this is the interface to your module. Anything included before the module declaration is not part of the module’s interface but rather merely an implementation detail. So this module will export the dog namespace and its woof function. Nothing else. Go ahead and compile it as follows:

Notice the module switch enables support for modules, much like the await switch enables support for coroutines. And since we’re not building an executable, the -c switch instructs the compiler not to involve the linker just yet. The compiler dutifully emits the module artifacts:

The .ifc file contains the metadata for the module. The compiler also produces an .obj file that is used to link the module to produce an executable. I can now write an app that relies on this module:

The import directive tells the compiler to look for the dog module and the main function can call the woof method without having to include any additional declarations. That’s pretty awesome! Compiling the app is also quite straitghtforward:

The compiler, with the help of the linker this time, successfully imports, compiles, and links the application:

The app prints woof:

There are a variety of other compiler switches to control search paths and other defaults, but this should get you started with modules in Visual C++ 2015 Update 1. Enjoy!

Update: The Visual C++ team just posted a more detailed description.