I'm trying to compile a simple empty module example (using gcc 11.2):
// my_module.cc:
export my_module;
// main.cc:
import my_module;
int main() { return 0; }
Using these compilation commands:
g++ my_module.cc -std=c++20 -fmodules-ts -c
g++ main.cc -std=c++20 -fmodules-ts my_module.o
This compiles fine.
However, even though the module is empty, I need the module's object file (my_module.o) when compiling main.cc, because the linker wants the function _ZGIW9my_moduleEv. I'm assuming this function is meant to perform initialization for static variables or something similar, as it will call __static_initialization_and_destruction_0 if I define static variables in the module.
My question is, does every module really need an object file? Is there any way to mark a named module as "doesn't need initialization, all my functions are inline"?
I think that header units could be used like this, but they're supposedly meant only as a transitory solution and have other downsides like macro hygiene.