howto:module_std_gcc15
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| howto:module_std_gcc15 [2026-04-09 16:48] – [How to use C++ module std in GNU g++-15] rrichter | howto:module_std_gcc15 [2026-05-03 11:13] (aktuell) – rrichter | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== How to use C++ module std in GNU g++-15 ====== | + | ====== How to use C++ module std in GNU g++ ====== |
| - | Follow this advice: https:// | + | g++-16: |
| + | g++ -std=c++26 -fmodules --compile-std-module hello.cpp | ||
| - | ==== CMake ==== | ||
| - | < | ||
| - | cmake_minimum_required(VERSION 3.31) | ||
| - | project( | + | g++-15: |
| - | compile_with_module_std | + | |
| - | VERSION 0.0.1 | + | |
| - | LANGUAGES CXX) | + | |
| - | + | ||
| - | # hack #1: temporary hack for GCC g++16.0 HEAD https:// | + | |
| - | # to remove when g++ & CMake know about module std | + | |
| - | add_library(module_std) | + | |
| - | + | ||
| - | target_sources(module_std | + | |
| - | PUBLIC | + | |
| - | FILE_SET CXX_MODULES FILES | + | |
| - | gnu/std.cc # copied from MinGW\include\c++\16.0.0\bits\std.cc | + | |
| - | ) | + | |
| - | target_compile_features(module_std PUBLIC cxx_std_26) | + | |
| - | # also to remove (see below): | + | |
| - | # target_link_libraries(...XYZ... PRIVATE module_std) | + | |
| - | + | ||
| - | # hack #2: advanced features like std::print(), std:: | + | |
| - | # target_link_libraries(...XYZ... PRIVATE stdc++exp) | + | |
| - | + | ||
| - | add_library(my_module) | + | |
| - | + | ||
| - | target_sources(my_module | + | |
| - | PUBLIC | + | |
| - | FILE_SET CXX_MODULES FILES | + | |
| - | src/my_module.cpp | + | |
| - | ) | + | |
| - | target_compile_features(my_module PUBLIC cxx_std_26) | + | |
| - | target_link_libraries(my_module PRIVATE module_std) # hack #1 | + | |
| - | + | ||
| - | add_executable(demo src/demo.cpp) | + | |
| - | target_compile_features(demo PUBLIC cxx_std_26) | + | |
| - | target_link_libraries(demo PRIVATE my_module) | + | |
| - | target_link_libraries(demo PRIVATE module_std) # hack #1 | + | |
| - | target_link_libraries(demo PRIVATE stdc++exp) | + | |
| - | + | ||
| - | </code> | + | |
| - | ==== C++ code ==== | + | |
| - | + | ||
| - | Modular '' | + | |
| - | + | ||
| - | <code cpp> | + | |
| - | export module my_first_module; | + | |
| - | import std; | + | |
| - | + | ||
| - | export namespace something | + | |
| - | { | + | |
| - | + | ||
| - | std::string hello(std:: | + | |
| - | { | + | |
| - | return " | + | |
| - | } | + | |
| - | + | ||
| - | } // end namespace something | + | |
| - | </ | + | |
| - | used in '' | + | |
| - | + | ||
| - | <code cpp> | + | |
| - | import std; | + | |
| - | import my_first_module; | + | |
| - | + | ||
| - | int main() | + | |
| - | { | + | |
| - | std:: | + | |
| - | } | + | |
| - | </ | + | |
howto/module_std_gcc15.1775746122.txt.gz · Zuletzt geändert: von rrichter
