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

    <legend id='fmrWR'><style id='fmrWR'><dir id='fmrWR'><q id='fmrWR'></q></dir></style></legend>
  2. <tfoot id='fmrWR'></tfoot>
  3. <small id='fmrWR'></small><noframes id='fmrWR'>

        <bdo id='fmrWR'></bdo><ul id='fmrWR'></ul>

      target_compile_options() 仅用于 C++ 文件?

      target_compile_options() for only C++ files?(target_compile_options() 仅用于 C++ 文件?)

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

                <tbody id='Gj82V'></tbody>
              <legend id='Gj82V'><style id='Gj82V'><dir id='Gj82V'><q id='Gj82V'></q></dir></style></legend>
            • <small id='Gj82V'></small><noframes id='Gj82V'>

              1. <tfoot id='Gj82V'></tfoot>
              2. 本文介绍了target_compile_options() 仅用于 C++ 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否可以仅将 target_compile_options() 用于 C++ 文件?我想将它用于作为其他应用程序依赖项的目标,以便库可以将其编译器标志传播到这些应用程序.但是,某些标志(例如 -std=c++14)如果与 C 或 ObjC 文件一起使用会导致构建失败.

                Is it possible to use target_compile_options() for only C++ files? I'd like to use it for a target that is uses as a dependency for other applications so that the library can propagate its compiler flags to those apps. However, there are certain flags, such as -std=c++14, that cause the build to fail if they are used with C or ObjC files.

                我已经读到我应该 CXX_FLAGS 而不是只将这些标志添加到 C++ 文件中,但是这不会(自动)通过 cmake 的包系统传播.

                I've read that I should CXX_FLAGS instead to only add those flags to C++ files, however this won't (automatically) propagate through cmake's packages system.

                推荐答案

                解决方案

                您可以使用生成器表达式:

                target_compile_options(MyLib PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-std=c++14>)
                

                替代方案

                但在这种特殊情况下,更独立于平台的方法是使用 target_compile_features().我不确定您使用的是哪个 编译器功能使用,所以以下只是一个例子:

                But the more platform independent way of doing it in this particular case would be to use target_compile_features(). I'm not sure which compiler feature you're using, so the following is only an example:

                target_compile_features(MyLib PUBLIC cxx_explicit_conversions)
                

                这篇关于target_compile_options() 仅用于 C++ 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)

                      <bdo id='4C4Sm'></bdo><ul id='4C4Sm'></ul>
                      <i id='4C4Sm'><tr id='4C4Sm'><dt id='4C4Sm'><q id='4C4Sm'><span id='4C4Sm'><b id='4C4Sm'><form id='4C4Sm'><ins id='4C4Sm'></ins><ul id='4C4Sm'></ul><sub id='4C4Sm'></sub></form><legend id='4C4Sm'></legend><bdo id='4C4Sm'><pre id='4C4Sm'><center id='4C4Sm'></center></pre></bdo></b><th id='4C4Sm'></th></span></q></dt></tr></i><div id='4C4Sm'><tfoot id='4C4Sm'></tfoot><dl id='4C4Sm'><fieldset id='4C4Sm'></fieldset></dl></div>
                    • <small id='4C4Sm'></small><noframes id='4C4Sm'>

                      <legend id='4C4Sm'><style id='4C4Sm'><dir id='4C4Sm'><q id='4C4Sm'></q></dir></style></legend><tfoot id='4C4Sm'></tfoot>

                          <tbody id='4C4Sm'></tbody>