<legend id='cSXl6'><style id='cSXl6'><dir id='cSXl6'><q id='cSXl6'></q></dir></style></legend>
      • <bdo id='cSXl6'></bdo><ul id='cSXl6'></ul>

      <small id='cSXl6'></small><noframes id='cSXl6'>

      <i id='cSXl6'><tr id='cSXl6'><dt id='cSXl6'><q id='cSXl6'><span id='cSXl6'><b id='cSXl6'><form id='cSXl6'><ins id='cSXl6'></ins><ul id='cSXl6'></ul><sub id='cSXl6'></sub></form><legend id='cSXl6'></legend><bdo id='cSXl6'><pre id='cSXl6'><center id='cSXl6'></center></pre></bdo></b><th id='cSXl6'></th></span></q></dt></tr></i><div id='cSXl6'><tfoot id='cSXl6'></tfoot><dl id='cSXl6'><fieldset id='cSXl6'></fieldset></dl></div>
    1. <tfoot id='cSXl6'></tfoot>

      如何在 CMake 中启用 C++17

      时间:2023-08-26
    2. <small id='FyXR2'></small><noframes id='FyXR2'>

      <legend id='FyXR2'><style id='FyXR2'><dir id='FyXR2'><q id='FyXR2'></q></dir></style></legend>
      <i id='FyXR2'><tr id='FyXR2'><dt id='FyXR2'><q id='FyXR2'><span id='FyXR2'><b id='FyXR2'><form id='FyXR2'><ins id='FyXR2'></ins><ul id='FyXR2'></ul><sub id='FyXR2'></sub></form><legend id='FyXR2'></legend><bdo id='FyXR2'><pre id='FyXR2'><center id='FyXR2'></center></pre></bdo></b><th id='FyXR2'></th></span></q></dt></tr></i><div id='FyXR2'><tfoot id='FyXR2'></tfoot><dl id='FyXR2'><fieldset id='FyXR2'></fieldset></dl></div>

        <tbody id='FyXR2'></tbody>

              • <bdo id='FyXR2'></bdo><ul id='FyXR2'></ul>
                <tfoot id='FyXR2'></tfoot>

              • 本文介绍了如何在 CMake 中启用 C++17的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我使用的是 VS 15.3,它支持集成的 CMake 3.8.如何在不为每个特定编译器编写标志的情况下以 C++17 为目标?我当前的全局设置不起作用:

                I'm using VS 15.3, which supports integrated CMake 3.8. How can I target C++17 without writing flags for each specific compilers? My current global settings don't work:

                # https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html
                set(CMAKE_CXX_STANDARD 17)
                set(CMAKE_CXX_STANDARD_REQUIRED ON)
                set(CMAKE_CXX_EXTENSIONS OFF)
                
                # expected behaviour
                #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++lastest")
                

                我希望 CMake 在生成 VS 解决方案文件时添加/std:c++lastest"或等效项,但未找到 c++17 标志,导致编译器错误:

                I expected CMake to add "/std:c++lastest" or equivalents when generating VS solution files, but no c++17 flags was found, resulted in compiler error:

                C1189 #error: class template optional is only available with C++17.
                

                推荐答案

                您的方法是正确的,但它不适用于 3.10 之前的 CMake 版本的 MSVC.

                Your approach is the correct one, but it will not work for MSVC on versions of CMake prior to 3.10.

                来自 CMake 3.9 文档:

                对于没有标准级别概念的编译器,例如 MSVC,这不起作用.

                For compilers that have no notion of a standard level, such as MSVC, this has no effect.

                简而言之,CMake 尚未更新以适应添加到 VC++ 2017 的标准标志.

                In short, CMake haven't been updated to accommodate for the standard flags added to VC++ 2017.

                您必须检测是否使用了 VC++ 2017(或更高版本)并暂时自行添加相应的标志.

                You have to detect if VC++ 2017 (or later) is used and add the corresponding flags yourself for now.

                在 CMake 3.10(及更高版本)中,此问题已针对较新版本的 VC++ 修复.请参阅3.10 文档.

                In CMake 3.10 (and later) this have been fixed for newer version of VC++. See the 3.10 documentation.

                这篇关于如何在 CMake 中启用 C++17的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用 CMAKE_EXPORT_COMPILE_COMMANDS? 下一篇:可以将导入的库添加到 target_link_libraries 来处理包含目录吗?

                相关文章

                <small id='lqgbF'></small><noframes id='lqgbF'>

                • <bdo id='lqgbF'></bdo><ul id='lqgbF'></ul>

                  <legend id='lqgbF'><style id='lqgbF'><dir id='lqgbF'><q id='lqgbF'></q></dir></style></legend>

                  <tfoot id='lqgbF'></tfoot>

                  1. <i id='lqgbF'><tr id='lqgbF'><dt id='lqgbF'><q id='lqgbF'><span id='lqgbF'><b id='lqgbF'><form id='lqgbF'><ins id='lqgbF'></ins><ul id='lqgbF'></ul><sub id='lqgbF'></sub></form><legend id='lqgbF'></legend><bdo id='lqgbF'><pre id='lqgbF'><center id='lqgbF'></center></pre></bdo></b><th id='lqgbF'></th></span></q></dt></tr></i><div id='lqgbF'><tfoot id='lqgbF'></tfoot><dl id='lqgbF'><fieldset id='lqgbF'></fieldset></dl></div>