简体   繁体   English

Ubuntu 20.04 和 Clang 13 上缺少 C++20 标头

[英]Missing C++20 headers on Ubuntu 20.04 with Clang 13

I have installed clang-13, but when I try to compile a program that uses C++20 headers, I get missing header errors.我已经安装了 clang-13,但是当我尝试编译一个使用 C++20 标头的程序时,我遇到了 header 错误。

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

It seems that CMake uses the system headers (from the old GCC headers shipped with ubuntu).似乎 CMake 使用系统标头(来自 ubuntu 附带的旧 GCC 标头)。 How do I convince it to use the Clang's headers instead?我如何说服它改用 Clang 的标头?

Numbers header is part of C++20 https://en.cppreference.com/w/cpp/header/numbers数字 header 是 C++20 的一部分https://en.cppreference.com/w/cpp/header/numbers

Installing the latest version of g++ fixed the issue for me.安装最新版本的 g++ 为我解决了这个问题。 For example, g++-11 is the latest version at the moment.例如,g++-11 是目前最新的版本。 To install it on Ubuntu:在 Ubuntu 上安装它:

Add the toolchain ppa to ensure that the latest version is available:添加工具链 ppa 以确保最新版本可用:

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您可以在这里查看最新版本: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM