How to use C++ 20 in g++
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
Related videos on Youtube

Admin
Updated on January 19, 2022Comments
-
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 saysg++: 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 over 1 yearYour version of
g++
is too old. You need at least 9+ forpopcount
(and that would be-std=c++2a
) or 10+ to be able to actually writec++20
. -
Brian over 1 yearWhat version of GCC are you using? Does it include C++20 support?
-
-
Kamil about 1 yearThere is also
-std=gnu++2a
-
xxllxx666 8 months"For G++ 9 and later" should be "For G++ 9 and earlier".