Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading