C++ Logo


Advanced search

clmod.py (the tool to provide easy use of module examples with Visual C++) is published

From: Nicolai Josuttis <nico_at_[hidden]>
Date: Sun, 17 Apr 2022 13:09:21 +0200
As promised, I have published a Python script at


The script circumvents the current restrictions of Visual C++ for simple
C++ example that want to test modules. I hope this contribution will
help to bring modules faster to life.

You can find the script with documentation and test code at the web
site. However let me mention a few basic aspects here.

Unlike Visual C++, the script

  * allows programmers to use arbitrary file suffixes for module units AND
  * does not require to specify options such as /internalPartition or
    /interface AND
  * enables programmers to pass ALL units of a C++ program using modules
    on ONE command line

As an example, assume for a module ModAll, we have:

  * *modall_if.cppm* : The module interface unit
  * *modall_ifpart.cppm* : An interface partition unit
  * *modall_part.cppm* : An internal partition
  * *modall_impl.cpp* : An implementation unit

and to test this we have:

  * *modall_test.cpp* : A traditional translation unit


|clmod.py /std:c++latest modall_part.cppm modall_ifpart.cppm
modall_if.cppm modall_impl.cpp modall_test.cpp /Femodall.exe |

will automatically do the right thing:

|cl /std:c++latest /Femodall.exe /TP /c /internalPartition
modall_part.cppm cl /std:c++latest /Femodall.exe /TP /c /interface
modall_ifpart.cppm cl /std:c++latest /Femodall.exe /TP /c /interface
modall_if.cppm cl /std:c++latest /Femodall.exe /TP /c modall_impl.cpp cl
/std:c++latest /Femodall.exe /TP /c modall_test.cpp cl /std:c++latest
/Femodall.exe modall_part.obj modall_ifpart.obj modall_if.obj
modall_impl.obj modall_test.obj |

Note that the order of the files still matters.

This example also works when using the Visual C++ conventions:

  * .ixx for interface units (all other with .cpp or so)
  * .cpp for all units (all gcc supports)

Thus, this script does not propose any file suffixes as a convention.

Instead, you now can use any convention to be able to have a first
portable C++ program using modules just passing all files to the compiler.

The script is not perfect. One drawback is that it requires compilation
by command line. The script is still a workaround until Visual C++
provides this support directly (which should be easy to do). But at
least you can now make easy experience with portable module examples not
using an IDE.

Hope this helps.

Feedback welcome (please cc me directly as I have not subscribed the
SG155 reflector).


Nicolai M. Josuttis
+49 (0)531 / 129 88 86
+49 (0)700 / JOSUTTIS
 C++: http://cppstd20.com, http://cppstd17.com, http://cppmove.com,
      http://cppstdlib.com, http://tmplbook.com

Received on 2022-04-17 11:09:30