gpt4 book ai didi

gradle NDK cmake 构建在链接期间失败

转载 作者:行者123 更新时间:2023-12-04 21:08:38 25 4
gpt4 key购买 nike

我正在构建一个非平凡的 android 库,使用 gradle android 构建工具 v2.2.0,它链接到十几个预构建的 .a 文件,输出应该是一个 .so 文件。试图从 ndk-build 转换至 cmake我无法正确链接 .so 文件,因为结果 ninja build 似乎无法找到静态库的头文件。

CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_VERBOSE_MAKEFILE on)

include_directories(${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/prebuilt/include )

add_library(precompiledA STATIC IMPORTED)
set_target_properties(precompiledA PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/dcmtk/lib/libprecompiledA.a)

add_library(precompiledB STATIC IMPORTED)
set_target_properties(precompiledB PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/dcmtk/lib/libprecompiledB.a)

add_library(precompiledC STATIC IMPORTED)
set_target_properties(precompiledC PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/dcmtk/lib/libprecompiledC.a)



add_library( jni-library

SHARED

hello.cpp )

find_library( log-lib
log )

target_link_libraries( jni-library

precompiledA
precompiledB
precompiledC

${log-lib} )

构建.gradle
apply plugin: 'com.android.library'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
minSdkVersion 19
targetSdkVersion 24

ndk {
abiFilters 'armeabi-v7a'
}

externalNativeBuild {
cmake {
arguments '-DANDROID_STL=gnustl_static',
'-DANDROID_CPP_FEATURES=exceptions'
}
}
}

externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

错误 - 缩写
ld: error: cannot find -lprecompiledA
undefined references galore...

在调用 gradle 时会生成 .o 文件,但在链接时,与静态库关联的 header 似乎丢失并且链接失败。是否可以选择告诉 cmake 链接时静态库头文件的位置?

最佳答案

更正 undefined reference

我犯的错误不是使用 target_include_directories ,未能给出库的绝对路径并忘记了 ${ANDROID_ABI}用于获取正确版本的二进制文件的变量。

cmake_minimum_required( VERSION 3.4.1 )

set( CMAKE_VERBOSE_MAKEFILE on )

add_library( precompiledA STATIC IMPORTED )
set_target_properties( precompiledA
PROPERTIES
IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/prebuilt_libs/mylib/lib/${ANDROID_ABI}/libprecompiledA.a )

add_library( precompiledB STATIC IMPORTED )
set_target_properties( precompiledB
PROPERTIES
IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/prebuilt_libs/mylib/lib/${ANDROID_ABI}/libprecompiledB.a )

add_library( precompiledC STATIC IMPORTED )
set_target_properties( precompiledC
PROPERTIES
IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/prebuilt_libs/mylib/lib/${ANDROID_ABI}/libprecompiledC.a )

find_library( log-lib
log )


target_include_directories( dicom-jni PRIVATE
prebuilt_libs/mylib/${ANDROID_ABI}/include )

add_library( jni-library
SHARED
hello.cpp )

target_link_libraries( jni-library

precompiledA
precompiledB
precompiledC

${log-lib} )

关于gradle NDK cmake 构建在链接期间失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39805580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com