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
13
u/not_a_novel_account cmake dev Mar 09 '26
The module object will always contain at least the global initialization symbol. Nominally this is always required to be linked, as
import <module>is supposed to always call this symbol.GCC and Clang have an optimization which omits this call for interfaces where they know the initialization is empty, but for correctness the produced object still needs to appear on the link line. Relying on a compiler optimization for the build to succeed is a code smell.