Preface
Welcome to A Pragmatic Journey into C++ Modules. I am a retired software developer who keeps my brain active by studying C++, especially the improvements made with modern C++, specifically C++ 20 and C++23. However, I still find interesting bits all the way back to C++11. I’m also keeping an eye on C++26. I enjoy testing the improvements and writing about them from the perspective of a hands-on developer. As a result, my writing doesn’t always cover all the nuanced whys of the material, just the pragmatic, it works.
Why Modules?
Modules are the most impactful new addition to C++20 since they affect every developer. The other Big Four—concepts, ranges, and coroutines affect major segments of C++ users but not necessarily everyone.
I explored ranges and presented on them twice at CppNorth, once in 2023 and again in 2024. I touched on concepts since the two are intertwined. I highly recommend CppNorth if you are in the Western Hemisphere and unable to travel beyond it. The group is friendly and casual. CppCon is also great but a little more intimidating because all the names are there.
Who This Book Is For
This book is for developers who want to use modules but don’t know how to do so. It is especially for those who tried to use them but were frustrated determining how to build them properly. It was frustrating, and it took me a lot of searching to refine the material on the command line and CMake builds.
Omnibus books on C++20 with sections on modules and conference talks about them are available. However, they are limited in scope, and frankly, some of the earlier material is outdated as compilers and build systems, like CMake, have decided how to implement modules. The work isn’t complete across all support systems but clarified sufficiently to begin working earnestly with modules. These works didn’t delve into the day-to-day details of working with modules, and the examples were limited in scope and size.
This book aims to provide a pragmatic discussion, working from the simplest to the most complex example I can manage. Along the way, it will touch on the detailed workings of modules and build systems, particularly for GCC, Clang, and CMake. I run Linux, so I can’t discuss MSVC specifically but most should apply. By the end, you will have a comprehensive understanding of C++20 modules to apply to your projects.
The material in this book is built and runs using GCC 14.2, Clang 18.1.8, 19.1.7 and 20.1, and CMake 28.5 and 31.0 — or later versions if I can get them before publication. I work in CLion, but all will be tested with command-line compilation and CMake. All the code, CMake files, and command lines are included. There is a lot of code in this book.
Use of AI
I used AI tools while writing the book, but all the text is mine. ChatGPT provided information and context on modules that were verified from other sources. I also used Grammarly as a copyeditor.
Both tools were helpful but the accuracy is inconsistent. ChatGPT sometimes cites out-of-date or wrong information about modules. I spent hours a few times chasing suggestions about using CMake with modules.
Grammarly often changes the meaning in offered suggestions but I rely heavily on it for copyediting.
Conventions Used in This Book
The typographic conventions used are:
Italic introduces new term.
Bold marks something notable.
Constant Width follows the standard convention for code in text or program listing.
![]() |
A section marked like this provides information both relevant and not. |
![]() |
A section marked like this is a caution to the unwary. |
Naming Examples by Cat Breed
Each example uses the name of a breed of cats. This is more interesting than the blah chapter one, chapter two, etc and also provides an alphabetical ordering for chapters and examples.
Another reason for my unique naming system is my preference for inclusive language. I wanted names that didn’t carry the weight of the often-used Foo and Bar, which have their obscene origins in military usage dating back to WWII. Although I’m 76, I appreciate the societal shift towards inclusivity and feel that these terms oppose that goal. For this same reason, a talk on ranges used ‘meow,’ inspiring it as my go-to for naming.

Another motivation is our cats, Six and Seven of Nine, which we brought home five years ago as kittens. We initially referred to them by the last digits of the shelter’s serial number, a temporary solution that stuck longer than expected. When the time for a vet visit arrived, I suggested names from Star Trek, a show my wife was unfamiliar with. The vet took it all in stride since her cats were named after Marvel characters.

