6

I have Eclipse Juno C++ ( Build id: 20120614-1722 ). I'm trying to set the compiler invocation arguments with instruction -std=c++11 or -std=c++0x but while compiling the code below. There is no "Tool Settings" in Eclipse Juno (at least for Mac), so I cannot go to "C/C++ Build -> Settings -> Tool Settings". My compiler is GCC 4.8.0

#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(void) {
    vector<string> v = {"a","b","c"};
    for(string s: v){
        cout << s << endl;
    }
    return 0;
}

I got:

HelloWorld.cpp:16:33: error: could not convert ‘{"a", "b", "c"}’ from ‘<brace-enclosed initializer list>’ to ‘std::vector<std::basic_string<char> >’
HelloWorld.cpp:17:16: error: range-based ‘for’ loops are not allowed in C++98 mode
Roman Kagan
  • 10,440
  • 26
  • 86
  • 126
  • 2
    What actual _compiler_ and standard library are you using? – ildjarn Jul 10 '12 at 19:18
  • 1
    did you ensure, that you set the options for g++ (and not a different part of the tool-chain) ? : do this: C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++0x at the end. – Carsten Greiner Jul 11 '12 at 04:36
  • There is no "Tool Settings" in Eclipse Juno. – Roman Kagan Jul 11 '12 at 20:38
  • Since GCC 4.8 is obviously not the standard system compiler, are you sure Eclipse actually calls that compiler when building and does not default to the system one? Unless your project is a Makefile project, you should have Project->Properties->C/C++ Build->Settings, and there is a tab for Tool Settings where you can configure the absolute path to the compiler as well as command line options. – jogojapan Jul 14 '12 at 10:17

3 Answers3

5

you might to follow the steps I described in this answer: Eclipse CDT C++11/C++0x support

One possibility is, that your options were applied to the wrong part of the tool chain.

Community
  • 1
  • 1
Carsten Greiner
  • 2,928
  • 2
  • 16
  • 20
0

I just faced exactly the same problem. Please check whether your project has a custom "makefile" ( *.mk ). If it has that "makefile", please put the following to your "makefile" and compile.

"LOCAL_CFLAGS := -fexceptions -std=c++0x -std=c++11"

PS: LOCAL_CFLAGS is for the compiler flags which you can put in "xxx > Miscellaneous". And to be frank, I don't know how to solve it if your project doesn't have custom "makefile". But, Eclipse Juno literally doesn't have the path the guys in the above described.

Aung Pyae
  • 1,590
  • 2
  • 16
  • 25
-1

The reason you don't see Tool Settings is because upon creating project, you should choose Executable instead of GNU Autotools

  • If you need and want autotools and configure it correctly your code compiles fine but eclipse still shows syntax errors. Choosing not to use autotools is no solution to the problem. – matthias krull Oct 29 '12 at 14:01