c++ - Why including atomic - gives errors -
i'm using g++ (gcc) version 4.9.2 under ubuntu 64 bit 14.04. i'm trying compile following simple code:
#include <iostream> #include <atomic> using namespace std; int main() { cout << "!!!hello world!!!" << endl; // prints !!!hello world!!! return 0; }
and following errors:
/usr/include/c++/4.9/atomic:385:56: error: ‘noexcept’ not name type memory_order __m = memory_order_seq_cst) volatile noexcept ^ /usr/include/c++/4.9/atomic:389:53: error: expected ‘;’ @ end of member declaration load(memory_order __m = memory_order_seq_cst) const noexcept ^ /usr/include/c++/4.9/atomic:389:59: error: ‘noexcept’ not name type load(memory_order __m = memory_order_seq_cst) const noexcept ^ /usr/include/c++/4.9/atomic:393:59: error: expected ‘;’ @ end of member declaration load(memory_order __m = memory_order_seq_cst) const volatile noexcept ^ /usr/include/c++/4.9/atomic:393:68: error: ‘noexcept’ not name type load(memory_order __m = memory_order_seq_cst) const volatile noexcept ^ /usr/include/c++/4.9/atomic:398:48: error: expected ‘;’ @ end of member declaration memory_order __m = memory_order_seq_cst) noexcept ^ /usr/include/c++/4.9/atomic:398:50: error: ‘noexcept’ not name type memory_order __m = memory_order_seq_cst) noexcept
why cant compile simple example ?
look @ first errors, not last ones. later errors caused earlier ones, looking @ last ones waste of time , doesn't tell root cause.
the first error be:
in file included /usr/include/c++/4.9/atomic:38:0, a.cc:2: /usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error file requires compiler , library support iso c++ 2011 standard. support experimental, , must enabled -std=c++11 or -std=gnu++11 compiler options.
this should totally obvious. didn't tell compiler want use c++11.
it tells how solve problems: compile -std=c++11
or -std=gnu++11
n.b. gcc 5 <atomic>
header modified only 1 error , not resulting fall-out comes after it.
Comments
Post a Comment