【问题标题】:QtCreator Cmake C++17 FeaturesQtCreator Cmake C++17 功能
【发布时间】:2018-01-29 12:28:15
【问题描述】:

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

一切正常,新功能为我的代码库增加了可观的价值。

但是,尝试在 qtcreator 中使用相同的编译器编译完全相同的项目会产生如下错误

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

如果尝试编译初始化程序-ifs。我尝试在 qtCreators 选项的 build&run 部分手动选择 gcc-7,但没有成功。所以我的问题是:

我必须在 IDE 中进行哪些调整才能使其符合这个最新标准?

【问题讨论】:

    标签: c++ qt cmake qt-creator c++17


    【解决方案1】:

    如果您在 Qt creator 中编译 Cmake 项目,请确保您的 CMakeLists.txt 中有这样一行:

    set(CMAKE_CXX_STANDARD 17)
    

    要使用 gcc-7.2.0,请确保它在 Tools/OptionBuild & Run 部分的 Compilers 选项卡中列出>。然后,在 Kits 选项卡中,选择您配置项目的工具包,并选择 gcc-7.2.0 作为工具包的编译器。

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

    QMAKE_CXXFLAGS += -std=c++17
    

    【讨论】:

    • 以某种方式工作,我现在能够编译 C++17 功能。但是,由于某些原因,IDE 现在将一堆代码行标记为详细错误。另外,我想知道在通过“sudo update-alternatives --config gcc”在我的终端中选择编译器版本时,在我的 CMakeLists.txt 中定义 C++ 版本或编译器版本的情况下,优先级是什么
    • target_compile_features(tgt PUBLIC cxx_std_17)怎么样
    猜你喜欢
    • 2018-03-18
    • 2018-11-04
    • 1970-01-01
    • 2021-03-04
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 1970-01-01
    相关资源
    最近更新 更多