6

I'm trying to compile some code using C++11 only syntax in JetBrains CLion, so I wish to disable C++98 mode. I followed the instructions accordance of this StackOverflow question, but am unable to get it working.

In order to achieve this goal, I went to ALT + SHIFT + F10 and passed the argument -std=c++11 in Program Arguments.

Upon building again, C++98 mode still seems to be enabled.

/cygdrive/c/Users/Zarthus/Documents/test/command.cpp: In constructor 'Command::Command(std::vector<std::basic_string<char> >)':
/cygdrive/c/Users/Zarthus/Documents/test/command.cpp:25:32: error: range-based 'for' loops are not allowed in C++98 mode
     for (std::string command : commands)
                                ^

in the code

Command::Command(std::vector<std::string> cmds)
{
    for (std::string command : cmds)
    {
         addCommand(command);
    }
}

Whilst I'm fairly certain the issue lies not within my code (IdeoneC++11 versus IdeoneC++98 (4.8.1))

Image: CLion Interface

What I'd imagine is the compilation string (per comments):

C:\cygwin64\bin\cmake.exe --build C:\Users\Zarthus\.clion10\system\cmake\generated\6dd8bed\6dd8bed\Debug --target testProject -- -j 4

So it does not appear it includes my content.

I've not a lot of experience with other JetBrains IDE's, but from what I could tell they're mostly the same.

Is anyone able to reproduce this? Should I send feedback to JetBrains that this may not be working 100% (it's still an early release build)? Or am I just botching it up and is there an user error here?

Thanks!

Community
  • 1
  • 1
Zarthus
  • 466
  • 6
  • 18
  • Never used CLion, but is there a way to see the what the g++ compiler is actually doing, i.e. a "verbose" mode? That way you can see if your arguments are being picked up but ignored, never picked up, etc. – PaulMcKenzie Sep 17 '14 at 20:31
  • @PaulMcKenzie I added a C:\cygwin64\bin\cmake.exe string - I'm not sure if that is exactly what you're looking for, but it's the best I could find. As for extra debug information - I could not find such option. – Zarthus Sep 17 '14 at 20:53
  • An IDE usually has a window or some means so that you can see the entire command line string that the compiler is using. Otherwise you're compiling blindly. The `cmake` uses a file, and inside that file has the command-string used by the compiler. Basically what you need to figure out is the exact command string used by the compiler, and then work from there. – PaulMcKenzie Sep 17 '14 at 20:58
  • Fairly obvious what you are doing wrong, you don't want to pass -std=c++11 to your own program. Keep looking, has something to do with CMake configuration. – Hans Passant Sep 17 '14 at 21:01
  • Thanks @PaulMcKenzie, I fixed it by adding `add_definitions(-std=c++11)` to the EOF of CMakeLists.txt - I wasn't aware CMake is basically my 'compilers' arguments. Thanks! – Zarthus Sep 17 '14 at 21:07

1 Answers1

8

This has been resolved by adding add_definitions(-std=c++11) to the end of CMakeLists.txt instead of in ALT+SHIFT+F10's command line arguments.

Zarthus
  • 466
  • 6
  • 18