Missing C++20 headers on Ubuntu 20.04 with Clang 13

Viewed 959

I have installed clang-13, but when I try to compile a program that uses C++20 headers, I get missing header errors.

#include <numeric>  
#include <numbers> // missing

It seems that CMake uses the system headers (from the old GCC headers shipped with ubuntu). How do I convince it to use the Clang's headers instead?

Numbers header is part of C++20 https://en.cppreference.com/w/cpp/header/numbers

1 Answers

Installing the latest version of g++ fixed the issue for me. For example, g++-11 is the latest version at the moment. To install it on Ubuntu:

Add the toolchain ppa to ensure that the latest version is available:

sudo add-apt-repository --update -y ppa:ubuntu-toolchain-r/test
sudo apt-get update -y

Then install

sudo apt-get -y --fix-broken install gcc-11 g++-11

You can check for the latest version here: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test

Related