CMake:link 选项
CMake: link options
我有一个 Android CMakeList.txt 定义了多个目标库(静态和动态)。
对于其中一个库,我需要传递带有特定版本脚本的 -Wl,--version-script ,为此我使用 target_link_libraries:
target_link_libraries( # Specifies the target library.
native-lib1
# Links the target library to the log library
# included in the NDK.
${log-lib}
-Wl,--version-script=${CMAKE_SOURCE_DIR}/../../../../../../native1.map
)
不幸的是,-Wl 选项被添加到我定位的所有其他库中,导致我出现任何类型的链接问题,因为 native1.map 仅引用 native-lib1 中的函数。
我也尝试过使用 target_link_options 和 add_link_options 但是 Android Studio returns 错误说这些不是有效的 CMake 命令。
有没有办法为 CMakeList.txt 中的单个库定义链接器选项?
我假设该选项在这里被视为 PUBLIC
。一般来说,我建议 always 在使用 target_***
命令时指定“可见性”。
但在这种情况下,我建议使用 target_link_options
,因为这样可以更清楚地说明意图。
target_link_libraries( # Specifies the target library.
native-lib1
# Links the target library to the log library
# included in the NDK.
${log-lib}
)
target_link_options(native-lib1
PRIVATE
"-Wl,--version-script=${CMAKE_SOURCE_DIR}/../../../../../../native1.map"
)
我有一个 Android CMakeList.txt 定义了多个目标库(静态和动态)。 对于其中一个库,我需要传递带有特定版本脚本的 -Wl,--version-script ,为此我使用 target_link_libraries:
target_link_libraries( # Specifies the target library.
native-lib1
# Links the target library to the log library
# included in the NDK.
${log-lib}
-Wl,--version-script=${CMAKE_SOURCE_DIR}/../../../../../../native1.map
)
不幸的是,-Wl 选项被添加到我定位的所有其他库中,导致我出现任何类型的链接问题,因为 native1.map 仅引用 native-lib1 中的函数。 我也尝试过使用 target_link_options 和 add_link_options 但是 Android Studio returns 错误说这些不是有效的 CMake 命令。
有没有办法为 CMakeList.txt 中的单个库定义链接器选项?
我假设该选项在这里被视为 PUBLIC
。一般来说,我建议 always 在使用 target_***
命令时指定“可见性”。
但在这种情况下,我建议使用 target_link_options
,因为这样可以更清楚地说明意图。
target_link_libraries( # Specifies the target library.
native-lib1
# Links the target library to the log library
# included in the NDK.
${log-lib}
)
target_link_options(native-lib1
PRIVATE
"-Wl,--version-script=${CMAKE_SOURCE_DIR}/../../../../../../native1.map"
)