Dar*_*rin 22 c++ ubuntu c++11 clang++
我遇到了在Ubuntu 16.04 LTS(服务器)上编译的问题.如果我不包括该-std=c++11位,它编译好.Clang版本是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.
Run Code Online (Sandbox Code Playgroud)
VZ.*_*VZ. 22
直到Mike Kinghan的回复中提到的Debian bug被修复,只需noexcept手动将缺少的(但必需的)规范添加到ctor定义中就可以解决问题,即你可以添加
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
_NOEXCEPT
#endif
Run Code Online (Sandbox Code Playgroud)
1938年之后/usr/include/c++/v1/string.
Mik*_*han 20
你已经libc++-dev在ubuntu 16.04上安装了(正确的)期望它应该让你用标准库的clang++使用libc++和它的标题构建.
它应该,但在std=c++11(或更高标准)的存在,它不,因为Debian bug#808086,你遇到过.
如果您希望使用clang++C++ 11标准或更高版本进行编译,那么在ubuntu为此获得修复之前,您将不得不libc++使用
libstdc++(GNU C++标准库),这是默认行为.
clang++ -std=c++11 foo.cpp
Run Code Online (Sandbox Code Playgroud)
要么:
clang++ -std=c++11 -stdlib=libstdc++ foo.cpp
Run Code Online (Sandbox Code Playgroud)
将工作.
| 归档时间: |
|
| 查看次数: |
5362 次 |
| 最近记录: |