Search code examples
c++gccc++23

How to enable c++23 on GNU GCC?


I want to run this hello world program which need C++23

import std;

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

I'm on a mac and i enter this into the terminal:

g++-13 -std=c++2b hello_world.cpp -o hello

also tried with -std=c++23

However it gives the error:

C++20 'import' only available with '-fmodules-ts', which is not yet enabled with '-std=c++20'

Why is it still on C++20?


Solution

  • You need to use the switch it specifies to use modules. It's not that it's trying to use C++20, it's that modules are not fully supported. Your switch for C++23 is correct, so it will use C++23.

    You can see the status here: https://gcc.gnu.org/projects/cxx-status.html#cxx20 which states "(requires -fmodules-ts)"

    However, also note that g++ does not yet support modules for the standard library. See the status here: https://en.cppreference.com/w/cpp/compiler_support#cpp23


    Edit: Jan 3, 2025

    Experimental support in G++15 with -fmodules