r/cpp • u/holyblackcat • Mar 09 '26
The compilation procedure for C++20 modules
https://holyblackcat.github.io/blog/2026/03/09/compiling-modules.html
103
Upvotes
r/cpp • u/holyblackcat • Mar 09 '26
View all comments
Show parent comment
1
u/not_a_novel_account cmake dev Mar 11 '26 edited Mar 11 '26
We shouldn't generate object files in multiple places. When using an imported target CMake will only generate BMIs, we assume the interface object has already been built and either linked into the associated shared library, or collected into the associated archive.
CMake does not model "interface-only" module libraries for this reason, there is always at least a global initialization symbol, which means there is always an object file, which means the library should always package either an archive or a shared object when it ships.
The problem is the stdlibs weren't doing that, so CMake actually models
import stdas a local target your project has to build. This has obvious ODR problems. I switched this to an imported library and we discovered that the MSVC STL and libstdc++ on MacOS really do needstd.o.