howto:modules_gcc11
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
— | howto:modules_gcc11 [2021-02-01 19:44] (aktuell) – angelegt - Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== How to use C++20 modules in GNU g++-11 ====== | ||
+ | |||
+ | using gcc11-20210124-32.exe (Windows build from [[http:// | ||
+ | |||
+ | ===== module definition ===== | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code cpp> | ||
+ | module; | ||
+ | #include < | ||
+ | // ... | ||
+ | </ | ||
+ | before '' | ||
+ | |||
+ | <code cpp greetings.cpp> | ||
+ | export module greetings; | ||
+ | import < | ||
+ | |||
+ | export auto say_hello() | ||
+ | { | ||
+ | std::cout << " | ||
+ | } | ||
+ | </ | ||
+ | ===== module interface unit ===== | ||
+ | |||
+ | Every module consists of exactly one module interface unit '' | ||
+ | |||
+ | ===== import module ===== | ||
+ | |||
+ | by its module name if you want to use the contents of a module | ||
+ | |||
+ | <code cpp main.cpp> | ||
+ | import greetings; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | say_hello(); | ||
+ | } | ||
+ | </ | ||
+ | ===== Prepare (std) header unit(s) ===== | ||
+ | |||
+ | before compiling modularized source code containing e.g. '' | ||
+ | |||
+ | < | ||
+ | g++ -fmodules-ts -std=c++20 -c -x c++-system-header iostream | ||
+ | </ | ||
+ | Other options are '' | ||
+ | ===== Compile program ===== | ||
+ | |||
+ | with option '' | ||
+ | |||
+ | < | ||
+ | g++ greetings.cpp main.cpp -fmodules-ts -std=c++20 | ||
+ | </ | ||
+ | Done! Start program: | ||
+ | |||
+ | < | ||
+ | > a.exe | ||
+ | Hello, modules! | ||
+ | </ | ||
+ | |||
+ | ===== Further reading ===== | ||
+ | * Nathan Sidwell: C++ Modules. A Brief Tour. Overload 28(159) 19-23, October 2020. https:// | ||
+ | |||
howto/modules_gcc11.txt · Zuletzt geändert: 2021-02-01 19:44 von 127.0.0.1