Run import std; with gcc successfully.
First I followed this link to get gcc import std; c++ working, https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Modules.html, but oops, when I removed the gcm.cache dir to test it, and repeated steps again, it did not work.
Then I found this link https://stackoverflow.com/questions/76154680/how-to-use-module-std-with-gcc, after I removed gcm.cache and did the steps again, it still worked.
Great, I can import std; with gcc now.
git clone --depth=1 git://gcc.gnu.org/git/gcc.git SomeLocalDir
Make an lazy alias gpp to the built & installed g++ program.
alias gpp=/path/to/g++
// test.cpp
import std; int main() { std::cout << "Hello c++!" << std::endl; }
Compile:
gpp -fmodules -fsearch-include-path bits/std.cc test.cpp -std=c++26 -o test
It is a little slow at the first time.
Compile:
gpp -fmodules test.cpp -std=c++26 -o test
It is much more fast by not specifying -fsearch-include-path bits/std.cc, when running not at the first time.
Remove gcm.cache and repeat above steps, it still works!
Mar 04, 2025
c++ std::exception:
std::cout.write(err.data(), err.size());
std::cout << std::endl;
caught:
=================================== # The c++ programming language. # # # # Join c++ # # Deck # ===================================