【问题标题】:linking to an executable under OSX with CMake使用 CMake 链接到 OSX 下的可执行文件
【发布时间】:2018-01-09 21:06:36
【问题描述】:

我有一个插件会被可执行文件加载。

可执行文件导出符号,这里是可执行文件的一些 CMake:

set_target_properties(rcrl_compiler_tests PROPERTIES ENABLE_EXPORTS ON)

然后我像这样链接到它:

target_link_libraries(test_plugin rcrl_compiler_tests)

这适用于 Windows 和 Linux。但对于 macOS,它不是。我读到我需要使用-bundle_loader,如ENABLE_EXPORTS 的文档中所述

所以我做了以下事情:

target_compile_options(test_plugin PRIVATE -Wl,-bundle_loader,$<TARGET_FILE:rcrl_compiler_tests>)

但是当我尝试编译插件时,我得到以下信息:

clang: 警告: -Wl,-bundle_loader,/Users/mario/rcrl/build/bin/rcrl_compiler_tests: 'linker' 输入未使用 [-Wunused-command-line-argument]

生成器表达式的可执行文件路径是正确的 - 但标志本身没有被使用。

对于我需要从可执行文件中导出并在插件中使用的仅有 2 个符号,我仍然遇到链接器错误。

知道如何解决这个问题吗?

【问题讨论】:

    标签: macos dll cmake linker dynamic-linking


    【解决方案1】:

    如果您使用-undefined dynamic_lookup,则不需要-bundle_loader

    只需将其用于链接标志:

    set_target_properties(TARGET PROPERTIES LINK_FLAGS "-undefined dynamic_lookup \
        -Wl,-no_pie \
        -Wl,-search_paths_first"
    )
    

    ...TARGET 是你的 dylib

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-16
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      相关资源
      最近更新 更多