2

So here I am, compiling my CMake-based C++ Projects in my terminal like there's not tomorrow with gcc-7.2.0 on Xubuntu 16.04 (via ppa)

Everything works fine and the new features add considerable value to my codebase.

However, trying to compile the very same project in qtcreator with the same compiler yields me errors like the following

: error: expected ‘)’ before ‘;’ token
   if (auto event = events_.find(eventName); event == end(events_)) {
                                           ^
: error: ‘else’ without a previous ‘if’
   } else {
     ^

if trying to compile initializer-ifs. I tried to manually pick gcc-7 in the build&run section in qtCreators options but without success. So my question is this:

What do I have to adjust in the IDE to make it conform to this latest standard?

Teivaz
  • 5,462
  • 4
  • 37
  • 75
CD86
  • 979
  • 10
  • 27

1 Answers1

4

If you're compiling Cmake projects in Qt creator, just be sure there is a line like this in your CMakeLists.txt:

set(CMAKE_CXX_STANDARD 17)

To use gcc-7.2.0, be sure it is listed in the Compilers tab of the Build & Run section in Tools/Option. Then, in Kits tab, select the kit you configured your project with, and select gcc-7.2.0 as the the kit's compiler.

If you're using qmake, instead, add this line to your pro file:

QMAKE_CXXFLAGS += -std=c++17
p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35
  • 2
    that worked somehow and I am able to compile C++17 features now. However, the IDE is marking a bunch of code lines now with verbose errors for some reasons oO. Also, I am wondering what takes precedence in the case that I define a C++ Version or compiler version in my CMakeLists.txt while selecting a compiler version in my terminal via "sudo update-alternatives --config gcc" – CD86 Jan 29 '18 at 13:00
  • what about `target_compile_features(tgt PUBLIC cxx_std_17)` – Mizux Jan 30 '18 at 12:22