I'm trying to run a simple program:
import <iostream>;
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
I've checked, and supposedly I've already have the newest version of gcc. build-essential is already the newest version (12.9ubuntu3).
I've tried running:
g++ -std=gnu++20 -o hello hello.cpp
or
gcc -std=c++20 -o hello hello.cpp
But both of them give me
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
1 | import <iostream>;
| ^~~~~~~~
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:9: error: ‘iostream’ was not declared in this scope
hello.cpp:1:1: error: ‘import’ does not name a type
1 | import <iostream>;
| ^~~~~~
hello.cpp:1:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
hello.cpp: In function ‘int main()’:
hello.cpp:4:6: error: ‘cout’ is not a member of ‘std’
4 | std::cout << "Hello, World!" << std::endl;
| ^~~~
hello.cpp:1:1: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
+++ |+#include <iostream>
1 | import <iostream>;
hello.cpp:4:38: error: ‘endl’ is not a member of ‘std’
4 | std::cout << "Hello, World!" << std::endl;
| ^~~~
hello.cpp:1:1: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’?
+++ |+#include <ostream>
1 | import <iostream>;
So then I ran: gcc -std=c++20 -fmodules-ts hello.cpp
Now I get
In module imported at hello.cpp:1:1:
/usr/include/c++/11/iostream: error: failed to read compiled module: No such file or directory
/usr/include/c++/11/iostream: note: compiled module file is ‘gcm.cache/./usr/include/c++/11/iostream.gcm’
/usr/include/c++/11/iostream: note: imports must be built before being imported
/usr/include/c++/11/iostream: fatal error: returning to the gate for a mechanical issue
compilation terminated.
I'm currently stuck here...