using gcc11-20210124-32.exe (Windows build from equation.com) (Warning: This is experimental!)
#include
headers in the global module fragment
module; #include <iostream> // ...
before module
module_name
;
or import
them after that:
export module greetings; import <iostream>; export auto say_hello() { std::cout << "Hello, modules!\n"; }
Every module consists of exactly one module interface unit export module
module_name
;
after which it declares which names should be export
ed, and eventually other module implementation units (source files) starting with module
module_name
;
(without export
).
by its module name if you want to use the contents of a module
import greetings; int main() { say_hello(); }
before compiling modularized source code containing e.g. import <iostream>;
g++ -fmodules-ts -std=c++20 -c -x c++-system-header iostream
Other options are c++-header
and c++-user-header
(uses #include
path).
with option -fmodules-ts
in c++20
mode:
g++ greetings.cpp main.cpp -fmodules-ts -std=c++20
Done! Start program:
> a.exe Hello, modules!