2017-06-16 33 views
6

我在运行ArchLinux的系统上使用clang版本4.0.0,它一直运行良好,但最近我无法编译使用某些STL标头的程序了!Clang无法编译使用<functional>标题的程序

详细说明:输出的

clang --version

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

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

+1

您是否尝试过重新排列包含的顺序?这有时会导致我的程序。或者试试如果removìng'#include '和'#include '帮助或导致不同的错误 –

+0

您似乎在使用gcc C++标准库。也许尝试使用叮当声。像'-stdlib = libC++'。 – juanchopanza

+0

@ThFl我删除了除“”以外的所有其他标题,问题依然存在。我将编辑原始问题。不过谢谢。 – nshct

回答

7

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

当您升级到gcc 7.1.1时,libstdC++(它是gcc的标准库)与它一起更新以提供来自C++ 17的新功能。使用gcc可以工作,因为它具有几乎完整的C++ 17支持。

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

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

+1

你刚刚解决了我一整天都很头疼的问题。 Clang和clang-tidy都在嘲笑'std :: thread {&Foo :: bar,this}'。事实证明,这是失败的课堂模板扣除。我现在可以吻你。 – maddisoj