Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this C++ program does not compile using modules?

Tags:

c++

module

Sorry if i ask again about "moudules" in C++. Im using g++ gcc-c++-12.2.1-4.fc37.x86_64 in fedora 37 linux and vscode. So i said: i will upgrade my knowladge with the book "A tour of C++ third edition" which its updated to c++20 standard.

The thing that the first program:

import std;
int main()
{
std::cout << "Hello, World!\n";
}

Doesn't compile. I have enabled "std=c++20" and "-fmodules-ts" and also tried "-std=gnu++20".

The output is this, its like the compiled modules are missing:

std: error: failed to read compiled module: No existe el fichero o el directorio
std: nota: compiled module file is ‘gcm.cache/std.gcm’
std: nota: imports must be built before being imported
std: error fatal: returning to the gate for a mechanical issue

Ok it's in spanish becouse is my native tongue. Any help?

like image 983
Lucas Avatar asked Oct 17 '25 13:10

Lucas


1 Answers

import std;

This line of code requires not only module support, but also Standard Library Modules (P2465R3 Standard Library Modules std and std.compat) that's part of C++23. From the Compiler support for C++23 page on cppreference, we can see that it's still not supported by GCC libstdc++.


As OP mentioned that the code snippet is taken from Bjarne's book, I double-checked section 1.2 of it. In the paragraph after the next from the code snippet containing import std;, it's stated that this is not yet standard:

The import directive is new in C++20 and presenting all of the standard library as a module std is not yet standard. [...]

like image 182
kotatsuyaki Avatar answered Oct 20 '25 04:10

kotatsuyaki



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!