【问题标题】:Android NDK install TARGETS given no RUNTIME DESTINATION for executable targetAndroid NDK 安装 TARGETS 没有给定可执行目标的 RUNTIME DESTINATION
【发布时间】:2018-09-19 01:40:16
【问题描述】:

我正在尝试在其中一个项目的 android 模块中导入外部 C/C++ 库。该库称为android-fluidsynth。我正在按照this link 的说明进行集成。以下是我的CMakeLists.txt 的样子:

EDIT 2:下面的工作

# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.

cmake_minimum_required(VERSION 3.4.1)


######################################################################################
######### Adding fluidsynth library from the external code
######################################################################################
# Sets lib_src_DIR to the path of the target CMake project.
set(fluidsynth-lib-name libfluidsynthsrc)
set( lib_DIR /Users/swapnilgupta/work/musicmuni/fluidsynth-android/android/ )

# Sets lib_build_DIR to the path of the desired output directory.
set( lib_build_DIR ${lib_DIR}/outputs )
file(MAKE_DIRECTORY ${lib_build_DIR})

# Adds the CMakeLists.txt file located in the specified directory
# as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
                  ${lib_DIR}

                  # Specifies the directory for the build outputs.
                  ${lib_build_DIR} )

# Adds the output of the additional CMake build as a prebuilt static
# library and names it.
add_library( ${fluidsynth-lib-name}
                SHARED
                IMPORTED )

set_target_properties( ${fluidsynth-lib-name} PROPERTIES IMPORTED_LOCATION
                       ${lib_build_DIR}/${ANDROID_ABI}/lib${fluidsynth-lib-name}.so )

在尝试构建时,我收到以下错误:

install TARGETS given no RUNTIME DESTINATION for executable target   "fluidsynth"

我浏览了一些 SO 帖子并在我的 CMakeLists.txt 中添加了以下几行,但我仍然收到此错误。

if(WIN32)
  install(TARGETS fluidsynth
    RUNTIME DESTINATION ./)
else()
  install(TARGETS fluidsynth
    LIBRARY DESTINATION ./)
endif()

有人可以帮忙吗?

【问题讨论】:

  • 错误信息似乎很清楚:fluidsynth 是一个可执行目标,因此它需要 RUNTIME DESTINATION。但是您的代码为非 Windows 平台设置了 LIBRARY DESTINATION。顺便说一句,您显示的代码不包含 fluidsynth 目标的创建,它只创建 libfluidsynth 一个。

标签: android c++ cmake android-ndk


【解决方案1】:

您无需为 libfluidsynth 发明自己的 CMakeLists.txt。您可以将您的 externalNativeBuild 指向 fluidsynth-android-1.1.10/android/CMakeLists.txt

这定义了 fluidsynth 库,您可以将其用作其他库的依赖项,例如

target_link_libraries(<mylibname> fluidsynth log)

【讨论】:

  • 我试过了,但它仍然在install 语句之一中显示错误。另外,当我在进入我有源代码所在的目录(即&lt;path&gt;/fluidsynth-android-1.1.10/src)后尝试运行cmake CMakeLists 时,我收到以下错误install TARGETS given no RUNTIME DESTINATION for executable target "fluidsynth". 我使用了以下https://stackoverflow.com/a/35756700/2606411 指令来构建它但不知道如何合并到我的 android 库中。
  • 不是 /fluidsynth-android-1.1.10/src,而是 /fluidsynth-android-1.1.10/android
  • 还有一个问题@Alex,如果我在我的add_library(...) 方法中提到了名称libfluidsynthsrc,使用set_target_properties( ${fluidsynth-lib-name} PROPERTIES IMPORTED_LOCATION ${lib_build_DIR}/${ANDROID_ABI}/lib${fluidsynth-lib-name}.so ) 是正确的还是我不应该在库名称前使用前缀lib仅供参考我使用了自定义 CMakeLists.txt,因为我想将此库与我在内部创建的另一个库链接!
  • 如果您使用fluidsynth-android-1.1.10/android/CMakeLists.txt 构建libfluidsynth,您可以将其用作库的依赖项,无需将其声明为IMPORTED。链接 CMakeLists.txt 文件很容易,它们有 add_subdirectory 命令。
  • 你的意思是我不必为流体合成器安卓1.1.10使用add_library()set_target_properties()?如果没有,那么我将如何尝试将其链接到我的图书馆。现在,我正在尝试使用 target_link_libraries(&lt;mylibname&gt; ${fluidsynth-lib-name} log) 使用流体合成器构建我的库。
【解决方案2】:

我在您的CMakeLists.txt 中看到两个问题:

一个小问题:set(runtime_destination) 语句没有作用,可以去掉。

另一个可能是你的构建绊倒:DYNAMIC 不是有效的 CMake 库类型,AFAIK。你应该把它改成SHARED

然后,由于它是一个导入的目标,您需要通过添加以下内容来指定其位置:

set_target_property(TARGET ${fluidsynth-lib-name} PROPERTY IMPORTED_LOCATION path-to-libfluidsynth.so)

【讨论】:

  • 嘿@Nicolas 谢谢你的回复。抱歉.. 我正在编辑,这就是为什么那个 'runtime_destination' 语句和我已经有一个 set_target_properties 语句。
猜你喜欢
  • 2022-12-11
  • 2013-02-06
  • 2015-08-27
  • 1970-01-01
  • 2011-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多