Member-only story

Rud Merriam
One Stop C++
Published in
4 min readFeb 5, 2025

--

A Small Journey into Modules for C++

I’ve been stalking StackOverflow lately, answering questions and commenting. Recently, a question on using modules appeared without many responses. This gave me the impetus to dig into modules, at least a little, which is something I’ve meant to do.

My environment is CLion, GCC 14.2, and CMake 28.3, the earliest version of CMake that supports modules.

I wanted to explore beyond simple main and module source file examples while using CLion with CMake. I also wanted to understand how to manage modules in a large project with many directories and files.

Module Terminology

As a starting point, here are some terminology and comments.

A Translation Unit (TU) is just a standard C++ source file. Technically, all of these are TUs.

A Module Interface Unit (MIU) declares the module and its exported entities. It is equivalent to a header file (.h or .hpp) in traditional C++. The file extensions sometimes used to distinguish these are .cppm or .ixx, but this is a convention, not a requirement of the compilers. Any file extension may be used.

I don’t like using a unique file extension. My technique uses the camel-case class name MyClass in headers declaring classes: MyClass.h. I will do the same for MIUs: MyModule.cpp. This allows the use of the lowercase version for Module Implementation Units.

--

--

One Stop C++
One Stop C++

Published in One Stop C++

Providing a Medium publication for stories on C++. No editing or review. Just publishing. If you write about C++ here is where to publish your story.

Rud Merriam
Rud Merriam

Written by Rud Merriam

I am a retired software engineer with decades of experience with embedded systems and have used C++ since the early 90s.

Responses (1)