there seems to be something wrong with my g++ compiler. It can't compile code with "-std=c++11" option on Ubuntu 16.04 with g++ 5.4.0.
So I write a really simple Hello World program :
//Hello.cpp
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World"<<endl;
}
If I compile it with g++ :
g++ Hello.cpp
it works fine.
But if I add "-std=c++11" :
g++ -std=c++11 Hello.cpp
g++ gives me tons of error message, more than 1000 lines.
Here is some of them:
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); }
^
Same code works fine on other computers.
Do you have any ideas?
error message above aren't the first line, the first line says:
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.
but even with "-std=c++1y" or "-std=gnu++1y" ,g++ still gives me a tons of error message.
libstdc++6 was installed on my system, and this isn't my first cpp program with "-std=c++11" on this PC(previously that works fine).
I don't remember what I have modified, but I'll try to reinstall my toolchain.
Thank you!
You have done something weird with your computer's package dependencies.
GCC 5 requires libstdc++ 6, but you have libstdc++ 5 (as shown in the paths).
This means your compiler and standard library implementation are not in sync.
Reinstall your toolchain.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.