C++ 获得一个基本的c++;使用clang++;在Ubuntu 16上

C++ 获得一个基本的c++;使用clang++;在Ubuntu 16上,c++,c++11,ubuntu,clang++,C++,C++11,Ubuntu,Clang++,我在Ubuntu 16.04 LTS(服务器)上编译时遇到问题。如果我没有包含-std=c++11位,那么它的编译就可以了。铿锵版本是3.8 >cat foo.cpp #include <string> #include <iostream> using namespace std; int main(int argc,char** argv) { string s(argv[0]); cout << s << endl;

我在Ubuntu 16.04 LTS(服务器)上编译时遇到问题。如果我没有包含
-std=c++11
位,那么它的编译就可以了。铿锵版本是3.8

>cat foo.cpp
#include <string>
#include <iostream>
using namespace std;

int main(int argc,char** argv) {
    string s(argv[0]);
    cout << s << endl;
}


>clang++ -std=c++11 -stdlib=libc++ foo.cpp
In file included from foo.cpp:1:
/usr/include/c++/v1/string:1938:44: error: 'basic_string<_CharT, _Traits, _Allocator>' is missing exception specification
      'noexcept(is_nothrow_copy_constructible<allocator_type>::value)'
basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
                                           ^
/usr/include/c++/v1/string:1326:40: note: previous declaration is here
    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
                                       ^
1 error generated.
>cat foo.cpp
#包括
#包括
使用名称空间std;
int main(int argc,字符**argv){
字符串s(argv[0]);

你可以在ubuntu 16.04上安装
libc++-dev
(正确)预期它应该安装吗 允许您使用
libc++
及其标题为您的 标准图书馆

它应该是这样的,但是在存在
std=c++11
(或更高版本的标准)的情况下 不,因为, 你遇到过的

如果希望使用
clang++
编译到C++11标准或更高版本,则 在ubuntu对此进行修复之前,您必须使用 <代码> LBSTDC++< /COD>(GNU C++标准库),而不是默认行为。

clang++ -std=c++11 foo.cpp
或:


将起作用。

直到Mike Kinghan回复中提到的Debian bug得到修复,只需将缺少的(但必需的)
noexcept
规范手动添加到ctor定义中,就可以解决问题,也就是说,只需添加

#if _LIBCPP_STD_VER <= 14
    _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
    _NOEXCEPT
#endif

#如果_LIBCPP_STD_VER在没有-stdlib=libc++的情况下工作,那么它会选择libstdc++头文件,而不是libc++。我认为这在linux发行版上是正常的。那么我如何让它使用libc++头文件呢?为什么不直接使用libstdc++@xaxxon对我来说,同样的问题是,使用gcc-4.8编译器时,我无法拥有c++14功能。使用clang而不是gcc是一个解决方案。请注意,在我做了这个更改之后,我还必须安装libc++abi-dev,然后安装ln-s/usr/include/libcxxabi/\uxxabi\u-config.h/usr/include/c++/v1/\uxxabi\u-config.html,我不必在Debian Sid下安装clang 3.8.0-2。我在Launchpad上重新打开了相同的错误。在Debian中,这只是一个小错误nconvenience as(截至今天)在实验中只提供了Clang3.8,Ubuntu16.04附带了Clang3.8和一个坏掉的libc++,这完全是胡说八道。这在16.04中得到了修复。
#if _LIBCPP_STD_VER <= 14
    _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
    _NOEXCEPT
#endif