【问题标题】:Pass option to compiler but not to the linker in cmake将选项传递给编译器,但不传递给 cmake 中的链接器
【发布时间】:2023-04-08 02:49:01
【问题描述】:

使用 cmake,可以将带有 CMAKE_CXX_FLAGSCMAKE_CXX_LINK_FLAGS 的编译器选项传递给链接器。

但据我所知,CMAKE_CXX_FLAGS 也被传递给链接器。

有没有办法将选项传递给编译器而不是链接器?

【问题讨论】:

标签: c++ cmake compilation linker flags


【解决方案1】:

使用 target_compile_options 将编译器选项添加到特定目标

https://cmake.org/cmake/help/latest/command/target_compile_options.html

使用 target_link_options 将链接器选项添加到特定目标

https://cmake.org/cmake/help/latest/command/target_link_options.html

现代 cmake 项目应避免使用 CMAKE_CXX_FLAGS/CMAKE_CXX_LINK_FLAGS,除非您真的知道自己在做什么。

【讨论】:

    猜你喜欢
    • 2021-10-10
    • 2017-11-01
    • 2013-12-01
    • 1970-01-01
    • 2019-08-08
    • 2015-09-26
    • 1970-01-01
    相关资源
    最近更新 更多