QtCreator Cmake C ++ 17功能 [英] QtCreator Cmake C++17 Features

查看:248
本文介绍了QtCreator Cmake C ++ 17功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在这里,在终端中编译基于CMake的C ++项目,就像明天没有在Xubuntu 16.04上使用gcc-7.2.0(通过ppa)

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.

但是,尝试使用相同的编译器在qtcreator中编译非常相同的项目会产生类似以下的错误

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 {
     ^

如果尝试编译initializer-ifs.我试图在qtCreators选项的build& run部分中手动选择gcc-7,但没有成功.所以我的问题是这样:

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:

为了使其符合最新标准,我需要在IDE中进行哪些调整?

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

推荐答案

如果要在Qt Creator中编译Cmake项目,只需确保在CMakeLists.txt中有这样一行:

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)

要使用gcc-7.2.0,请确保将其列在 Build&的 Compilers 标签中.工具/选项中的运行部分.然后,在工具包选项卡中,选择用于配置项目的工具包,然后选择gcc-7.2.0作为工具包的编译器.

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.

如果您使用的是qmake,请将此行添加到您的 pro 文件中:

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

QMAKE_CXXFLAGS += -std=c++17

这篇关于QtCreator Cmake C ++ 17功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆