namespace cpp

C++ lernen, kennen, anwenden

Benutzer-Werkzeuge

Webseiten-Werkzeuge


howto:modules_gcc11

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
howto:modules_gcc11 [2021-02-01 19:13]
rrichter angelegt
howto:modules_gcc11 [2021-02-01 19:44]
rrichter [Compile program]
Zeile 1: Zeile 1:
-====== How to use C++modules in GNU g++-11 ======+====== How to use C++20 modules in GNU g++-11 ======
  
-using gcc11-20210124-32.exe (Windows build on http:%%//%%www.equation.com/servlet/equation.cmd?fa=fortran)+using gcc11-20210124-32.exe (Windows build from [[http://www.equation.com/servlet/equation.cmd?fa=fortran|equation.com]]) (Warning: This is experimental!)
  
 ===== module definition ===== ===== module definition =====
Zeile 12: Zeile 12:
 // ... // ...
 </code> </code>
-before ''%%module%%''//''%%module_name%%''//''%%;%%'' or ''%%import%%'' them after that:+before ''module'' //''module_name''//'';'' or ''import'' them after that:
  
-<code cpp>+<code cpp greetings.cpp>
 export module greetings; export module greetings;
 import <iostream>;   import <iostream>;  
Zeile 25: Zeile 25:
 ===== module interface unit ===== ===== module interface unit =====
  
-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%%'').+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'').
  
 ===== import module ===== ===== import module =====
Zeile 31: Zeile 31:
 by its module name if you want to use the contents of a module by its module name if you want to use the contents of a module
  
-<code cpp>+<code cpp main.cpp>
 import greetings; import greetings;
  
Zeile 39: Zeile 39:
 } }
 </code> </code>
-===== Prepare std header unit(s) =====+===== Prepare (stdheader unit(s) =====
  
-before compiling modularized source code containing e.g. ''%%import <iostream>;%%''+before compiling modularized source code containing e.g. ''import <iostream>;''
  
 <code> <code>
-g++ -fmodule-header -std=c++20 -x c++ c:\gcc\include\c++\11.0.0\iostream+g++ -fmodules-ts -std=c++20 -c -x c++-system-header iostream
 </code> </code>
-(adapt the path to include files on your system …) +Other options are ''c++-header'' and ''c++-user-header'' (uses ''#include'' path).
 ===== Compile program ===== ===== Compile program =====
  
-with option ''%%-fmodules-ts%%'' in ''%%c++20%%'' mode:+with option ''-fmodules-ts'' in ''c++20'' mode:
  
 <code> <code>
Zeile 61: Zeile 60:
 Hello, modules! Hello, modules!
 </code> </code>
 +
 +===== Further reading =====
 +  * Nathan Sidwell: C++ Modules. A Brief Tour. Overload 28(159) 19-23, October 2020. https://accu.org/journals/overload/28/159/sidwell
 + 
  
howto/modules_gcc11.txt · Zuletzt geändert: 2021-02-01 19:44 von rrichter