Clang无法使用< functional>标头了 [英] Clang can't compile programs using the <functional> header anymore

查看:76
本文介绍了Clang无法使用< functional>标头了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行ArchLinux的系统上使用 clang 版本4.0.0,它始终可以正常工作,但是最近我无法再编译使用某些STL标头的程序!

I'm using clang Version 4.0.0 on my system running ArchLinux, it always worked fine, but recently I can't compile programs that use certain STL headers anymore!

详细信息:

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

示例:

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

I tried compiling the following trivial program:

#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中的错误还是我的设置搞砸了?

Is this a bug in the STL or is my setup messed up?

推荐答案

您的设置被弄乱了。有趣的是,我也有同样的问题。

Your setup is messed up. Funny enough, I have the exact same problem.

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

When you upgraded to gcc 7.1.1, libstdc++ (which is gcc's Standard Library) was updated alongside of it to provide the new features from C++17. Using gcc, this works, because it has almost full C++17 support.

但是clang不能。提示是 -std = c ++ 1z 标志,而不是gcc的 -std = c ++ 17 标志。 Clang缺少演绎指南,当它在libstdc ++中遇到时,它不会

But clang doesn't. A hint is the -std=c++1z flag instead of gcc's -std=c++17 flag. Clang is missing deduction guides, and when it encounters them in libstdc++, it doesn't know what to do with them.

您可以从ALA安装旧的libstdc ++软件包,也可以下载/使用LLVM的标准库 libc ++ ,它自然仅具有部分C ++ 17功能。

You can install the old libstdc++ package from the ALA, or you can download/use LLVM's Standard Library libc++, which naturally has only partial C++17 features.

这篇关于Clang无法使用&lt; functional&gt;标头了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆