【发布时间】:2017-12-12 02:46:32
【问题描述】:
我在运行 ArchLinux 的系统上使用 clang 版本 4.0.0,它一直运行良好,但最近我无法编译使用某些 STL 头文件的程序了!
详情:
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 中的错误还是我的设置搞砸了?
【问题讨论】:
-
您是否尝试过重新排列包含的顺序?这就是有时为我带来程序的原因。或者尝试删除
#include <iostream>和#include <type_traits>是否有助于或导致不同的错误 -
您似乎在使用 gcc c++ 标准库。也许尝试使用铿锵声。类似
-stdlib=libc++. -
@ThFl 我删除了除
<functional>以外的所有其他标头,但问题仍然存在。我将编辑原始问题。不过还是谢谢。 -
@nshct 您能否将
clang --version和gcc --version的输出添加到您的问题中(主要针对未来的读者)? -
@Holt 是的,我已经添加了它。谢谢。