简体   繁体   中英

Eclipse / g++ not recognizing “-std=c++11” flag

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

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM