Read:
gcc import std; c++ modules (03-04, 2025)
alias gpp="/path/to/g++ -fmodules-ts -std=c++26"
c++ module declaration starts with a keyword export
or module
.
E.X:
export module module-name;
Declares a primary module interface unit and export, its name is module-name
.
my_class.cpp :
export module my_space; import std; export namespace my_space { class my_class { private: int __x; public: my_class(): __x{123} { } my_class(int x__): __x{x__} { } int get() const { return __x; } void greeting() const { std::cout << "Cheers, c++!" << std::endl; } }; }
Build it to shared library:
gpp my_class.cpp -c -shared -o libmy_class.so
import my_space; import std; int main() { my_space::my_class obj1; my_space::my_class obj2{-234}; std::cout << "values:\n" << obj1.get() << '\n' << obj2.get() << "\n"; obj2.greeting(); std::cout << std::endl; }
Build program:
gpp main.cpp -L./ -lmy_class -o main
Run program:
> ./main values: 123 -234 Cheers, c++!
April 23, 2025
c++ std::exception:
std::cout.write(err.data(), err.size());
std::cout << std::endl;
caught:
=================================== # The c++ programming language. # # # # Join c++ # # Deck # ===================================