QtCreator Cmake C++17 Features

假装没事ソ 提交于 2020-03-22 09:39:19

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/48501290/qtcreator-cmake-c17-features

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!