3

I am running CentOS 6.6 x64 with Eclipse Luna and g++ 4.7.2 (provided by devtoolset-2). I'm using Eclipse's built in automatic Makefile generation.

I've enabled g++ 4.7.2 using scl enable devtoolset-2 bash

[me@dev ~]# g++ --version g++ (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5) Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Unfortunately, when compiling, Eclipse is throwing errors saying "-std=c++11" isn't a valid option. I've set the dialect under the project properties >> C/C++ Build >> Settings >> Dialect >> "Other dialect flags" with the value "-std=c++11".

Invoking: GCC C++ Compiler make: *** Waiting for unfinished jobs.... g++ -std=c++11 .... cc1plus: error: unrecognized command line option "-std=c++11"

I've tried using the "Language Standard" option with "-std=c++0x", but it throws errors when compiling

map<int, MyObject*> myObjectMap; 
// assume I've added in objects before the loop
for (const auto& kv : myObjectMap) // line 249
{
    // do things
}

249: error: expected initializer before ‘:’ token

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
thaspius
  • 1,135
  • 3
  • 17
  • 33
  • Hm, range-for was introduced in gcc 4.6, so this should work with `-std=c++0x`. Can you post an [SSCCE](http://www.sscce.org)? – Baum mit Augen Jun 02 '15 at 18:46
  • Get a newer version of GCC. c++11 was experimental in version 4.7.x IIRC. The option `-std=c++0x` should work to have those experimental features enabled. – πάντα ῥεῖ Jun 02 '15 at 18:46
  • GCC 4.7 should understand both the command-line option `-std=c++11` and the code including range-based for-loops. Have you started Eclipse from the shell where you enabled the devtoolset? – Daniel Frey Jun 02 '15 at 18:47
  • 1
    Can you try a build straight from the command-line? – Raz0r Jun 02 '15 at 18:48
  • Ugh... thats the issue, I wasn't understanding exactly what the scl enable command was doing. – thaspius Jun 02 '15 at 18:48
  • Yea. Ran it from the right shell and it compiles as it should. I'll just need to create a shell script or something to boot up eclipse with that set. – thaspius Jun 02 '15 at 18:50
  • 1
    @thaspius Ah. Well the `devtoolset` installs a new development environment *in parallel* to the existing one. The default is still the old one, the new one is only active when you change the environment. Eclipse needs to be aware which one to use. And BTW: Consider using `devtoolset-2.1` if possible as this is also what RHEL7 (and the Centos equivalent) are using. – Daniel Frey Jun 02 '15 at 18:51
  • I'll look into devtoolset 2.1. Thanks. Post your answer if you want and I'll accept it. – thaspius Jun 02 '15 at 18:54

1 Answers1

3

If you want Eclipse to work with the installed devtoolset-2, you need to start Eclipse from an environment which has the devtoolset enabled. Most obviously this can be done from a terminal with

scl enable devtoolset-2 eclipse &

To explain: The devtoolset is installed as an alternative development environment which is not active by default. Only when explicitly activated, you will get the new compiler version which understands -std=c++11 and the features you were looking for.

Daniel Frey
  • 55,810
  • 13
  • 122
  • 180