gpt4 book ai didi

c++ - Clang 无法再使用 header 编译程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:33 27 4
gpt4 key购买 nike

我在运行 ArchLinux 的系统上使用 clang 版本 4.0.0,它一直运行良好,但最近我无法再编译使用某些 STL header 的程序了!

详细信息:

clang --version 的输出:

 clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

gcc --version 的输出:

 gcc (GCC) 7.1.1 20170528

示例:

我尝试编译以下简单程序:

#include <functional>

int main()
{
return 0;
}

我正在使用以下命令:

clang++ -std=c++1z test.cxx

结果是失败:

In file included from test.cxx:3:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/functional:60:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/unordered_map:47:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/bits/hashtable.h:37:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/bits/node_handle.h:39:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:27: error: use of
class template 'optional' requires template arguments
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:451:11: note: template
is declared here
class optional
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:40: error:
expected ';' at end of declaration
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/optional:1032:41: error: cannot
use arrow operator on a type
template <typename _Tp> optional(_Tp) -> optional<_Tp>;
^
3 errors generated.

这是 STL 中的错误还是我的设置搞砸了?

最佳答案

你的设置搞砸了。有趣的是,我有完全相同的问题。

当您升级到 gcc 7.1.1 时,libstdc++(它是 gcc 的标准库)也随之更新,以提供 C++17 的新功能。使用 gcc,这是可行的,因为它具有几乎完整的 C++17 支持。

但是 clang 没有。提示是 -std=c++1z 标志而不是 gcc 的 -std=c++17 标志。缺少 Clang deduction guides ,当它在 libstdc++ 中遇到它们时,它不知道如何处理它们。

您可以从 ALA 安装旧的 libstdc++ 包,或者您可以下载/使用 LLVM 的标准库 libc++ ,它自然只有部分 C++17 特性。

关于c++ - Clang 无法再使用 <functional> header 编译程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44584289/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com