Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use module `std` with gcc

The following test program

import std;
int main() {}

compiled with gcc-14

/usr/local/bin/g++  -g -std=c++23 -fconcepts -fmodules-ts -O3 -Wall -Wextra test400.cc --output test400

gives the following errors:

std: error: failed to read compiled module: No such file or directory
std: note: compiled module file is 'gcm.cache/std.gcm'
std: note: imports must be built before being imported
std: fatal error: returning to the gate for a mechanical issue

The standard library module std should be available, but obviously is not.

Aside from header units: is the a way to create the std module by my own?

like image 443
wimalopaan Avatar asked Feb 24 '26 03:02

wimalopaan


2 Answers

GCC 15.0 supports it with -fsearch-include-path bits/std.cc.

g++ -std=c++20 -fmodules -fsearch-include-path bits/std.cc file.cpp

That will take a few seconds, once it’s done you'll have a cache file at gcm.cache/std.gcm. You’ll then be able to compile faster by removing -fsearch-include-path bits/std.cc from your command.

g++ -std=c++20 -fmodules file.cpp

References:

  • Commit adding std module
  • Commit adding -fsearch-include-path
  • Commit renaming -fmodules-ts to -fmodules
like image 51
Alexandre Dieulot Avatar answered Feb 25 '26 17:02

Alexandre Dieulot


GCC's libstdc++ does not support P2465R3 yet, which allows for import std;

https://en.cppreference.com/w/cpp/compiler_support/23

Note that C++23 is not yet finalized

like image 20
ChrisMM Avatar answered Feb 25 '26 17:02

ChrisMM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!