我的g ++编译器似乎有问题。它不能用" -std = c ++ 11"编译代码。使用g ++ 5.4.0在Ubuntu 16.04上选项。
所以我写了一个非常简单的Hello World程序:
//Hello.cpp
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World"<<endl;
}
如果我用g ++编译它:
g ++ Hello.cpp
它工作正常。
但如果我添加&#34; -std = c ++ 11&#34; :
g ++ -std = c ++ 11 Hello.cpp
g ++给了我很多错误信息,超过1000行。
以下是其中一些:
In file included from /usr/include/c++/5/bits/stl_pair.h:59:0,
from /usr/include/c++/5/bits/stl_algobase.h:64,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from Hello.cpp:1:
/usr/include/c++/5/bits/move.h:76:27: error: ‘remove_reference’ in namespace ‘std’ does not name a template type
forward(typename std::remove_reference<_Tp>::type& __t) noexcept
^
/usr/include/c++/5/bits/move.h:76:43: error: expected ‘,’ or ‘...’ before ‘<’ token
forward(typename std::remove_reference<_Tp>::type& __t) noexcept
^
/usr/include/c++/5/bits/move.h: In function ‘constexpr _Tp&& std::forward(int)’:
/usr/include/c++/5/bits/move.h:77:33: error: ‘__t’ was not declared in this scope
{ return static_cast<_Tp&&>(__t); }
^
相同的代码在其他计算机上运行良好。
你有什么想法吗?
上面的错误信息不是第一行,第一行是:
In file included from
/usr/include/c++/5/experimental/type_traits:39:0,
from /usr/include/c++/5/bits/move.h:57,
from /usr/include/c++/5/bits/stl_pair.h:59,
from /usr/include/c++/5/bits/stl_algobase.h:64,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from Hello.cc:1:
/usr/include/c++/5/bits/c++14_warning.h:32:2: error: #error This file requires compiler and library support for the forthcoming ISO C++ 2014 standard.
This support is currently experimental, and must be enabled with the -std=c++1y or -std=gnu++1y compiler options.
但即使是&#34; -std = c ++ 1y&#34;或&#34; -std = gnu ++ 1y&#34; ,g ++仍然给我一些错误信息。
libstdc ++ 6安装在我的系统上,这不是我的第一个cpp程序&#34; -std = c ++ 11&#34;在这台电脑上(以前工作正常)。
我不记得我修改了什么,但我会尝试重新安装我的工具链。
谢谢!
答案 0 :(得分:8)
您对计算机的软件包依赖性做了一些奇怪的事情。
GCC 5需要libstdc ++ 6,但你有libstdc ++ 5(如路径所示)。
这意味着您的编译器和标准库实现不同步。
重新安装工具链。