Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-std=c++11 flag unrecognized in gcc/g++ 4.4.6

I have some code written using the C++11 standards, and our g++ version is 4.4.6, so as far as I can tell, C++11 should be supported (from 4.3 onwards).

However upon trying to compile with the flags -std=c++11 -std=gnu++11, I get repetitions of the errors

cc1plus: error: unrecognized command line option `-std=c++11`
cc1plus: error: unrecognized command line option `-std=gnu++11`

Compiling with -std=c++0x produces errors such as

DeviceInfo.cpp:22: error: expected initializer before ‘:’ token

corresponding to this line of code:

for (cl::Platform& plat : platforms)

Is this a C++11 specific bit of Syntax? (it doesn't look like it to me, but all this code has been given as an example so should work as provided with the compiler.)

Any help?

like image 562
Joe Avatar asked May 09 '13 07:05

Joe


2 Answers

-std=c++11 setting is supported by much later versions of GCC. The initial support for nascent C++11 was enabled by -std=c++0x setting. This is probably what you should try.

And yes, the for syntax you are trying to use is chiefly C++11 syntax.

like image 98
AnT Avatar answered Sep 20 '22 06:09

AnT


It appears as if range-based for loops are supported in 4.6 and newer.

This page shows GCC support for C++11 features.

like image 33
avlouis Avatar answered Sep 19 '22 06:09

avlouis