g++c++23

c++23 "Hello World" not compiling


I am using the latest version of g++, i.e. version 14.2 on Ubuntu 24.04. When I compile, the "Hello World" code, I get some errors. I am new to c++ and I will appreciate a guiding hand. I can rewrite the code to be conform with c++20 and compile it without problem, but I want to try c++23.

Here is the code:

import std;
using namespace std;

int main(){
    println("Hello World");

}

Here is how I compile and the errors:

hakiza@VBox:~/cpp/ppp/ch00$ g++ -std=c++2b helloWorld.cpp -o hello
helloWorld.cpp:1:1: error: ‘import’ does not name a type
    1 | import std;
      | ^~~~~~
helloWorld.cpp:1:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’
helloWorld.cpp: In function ‘int main()’:
helloWorld.cpp:5:5: error: ‘println’ was not declared in this scope
    5 |     println("Hello World");
      |     ^~~~~~~

Here is the g++ version:

hakiza@VBox:~/cpp/ppp/ch00$ g++ --version
g++ (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Solution

  • After some googling, I found the answer by @ChrisMM in this post: "GCC's libstdc++ does not support P2465R3 yet, which allows for import std;". One can get the same answer from compiler_support for c++23.