How to use C++ 20 in g++

13,332

Solution 1

I would try updating gcc. C++ 20 was introduced in gcc version 8 which is pretty new.

Solution 2

C++20 features are available since GCC 8.

To enable C++20 support, add the command-line parameter

-std=c++20

For G++ 9 and later use

-std=c++2a

Or, to enable GNU extensions in addition to C++20 features, add

-std=gnu++20

Solution 3

If it's an option you can update to Ubuntu 20.04 LTS which includes GCC version 9 out of the box. This would enable you to use C++ 20 and thus std::popcount

Note: use -std=c++2a in GCC 9 and earlier

Share:
13,332

Related videos on Youtube

Admin
Author by

Admin

Updated on January 19, 2022

Comments

  • Admin
    Admin 11 months

    I am trying to access std::popcount, but it seems like it's only there in C++ 20.

    When I try compiling with g++ -std=c++20 main.cpp, it says g++: error: unrecognized command line option '-std=c++20'; did you mean '-std=c++03'

    How do I tell g++ to use c++ 20?

    I am using Ubuntu 18.04

    • Barry
      Barry over 1 year
      Your version of g++ is too old. You need at least 9+ for popcount (and that would be -std=c++2a) or 10+ to be able to actually write c++20.
    • Brian
      Brian over 1 year
      What version of GCC are you using? Does it include C++20 support?
  • Kamil
    Kamil about 1 year
    There is also -std=gnu++2a
  • xxllxx666
    xxllxx666 8 months
    "For G++ 9 and later" should be "For G++ 9 and earlier".

Related