wimalopaan
wimalopaan

Reputation: 5462

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?

Upvotes: 12

Views: 8623

Answers (2)

Alexandre Dieulot
Alexandre Dieulot

Reputation: 524

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

gcc -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.

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

References:

Upvotes: 2

ChrisMM
ChrisMM

Reputation: 10021

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

Upvotes: 8

Related Questions