Why am I missing C++20 headers? And how do I fix this?
Asked Answered
D

1

9

I've been Googling around for months trying to solve this, but nothing I've tried works.

So a simple program like this:

#include <concepts>
#include <iostream>

int main() {
    std::cout << "Test" << std::endl;
    return 0;
}

fails to compile with the error message fatal error: 'concepts' file not found. This happens with both clang++ and g++ compilers. (For completeness: clang++-11 -std=c++20 test.cpp and g++ -std=c++2a test.cpp.)

My compiler versions are:

> clang++-11 --version
Ubuntu clang version 11.0.0-2~ubuntu20.04.1

> g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

If I look for my C++ headers, I can find them in /usr/include/c++:

> find /usr -name "iostream"
/usr/lib/llvm-10/include/c++/v1/iostream
/usr/include/c++/9/iostream

However, find /usr -name "concepts" gives nothing. So the header is definitely missing. Along with all the other C++20-specific headers, and C++20-specific functions that are defined in other headers (like [std::bit_width][1] for example - the header can be included but the function is not defined).

And by the way, I can use all C++20 functionality. For example, I can define my own concepts, although I can't use the concepts header.

What's weird is everywhere I Google for this type of issue, the only problems I can find are people who are using an old compiler that doesn't support C++20, or are missing all C++ headers (or the compiler can't find them). But I'm not sure what I'm supposed to do given that my compiler clearly supports C++20, yet I'm missing the C++20 headers.

I did try to see if libstdc++ needed an update, but to no avail:

> sudo apt install libc++-dev
[...]
libc++-dev is already the newest version (1:10.0-50~exp1).
Doorstep answered 2/9, 2021 at 23:8 Comment(2)
There's a nice feature test program (in the example area) that you can compile and run using C++20 and the resulting program will tell you which C++20 features are available in your particular compiler. (Many compilers are not 100% complete in their C++20 implementations yet.)Rani
gcc supports concepts since version 10.Dominant
D
7

So I needed g++ version 10 installed to get the required headers. I thought I had the latest version of everything, but I think I may have updated gcc rather than g++. To anyone having this issue, make sure to double check your g++ --version, not gcc --version in case they are different.

Anyway, the following solved the issue:

sudo apt install g++-10

Doorstep answered 3/9, 2021 at 22:59 Comment(1)
clang-11.0.0 with -stdlib=libc++ manages to find #include <concepts>: gcc.godbolt.org/z/5PMqahzfvShamekashameless

© 2022 - 2024 — McMap. All rights reserved.