我正在构建一个非常复杂的Android库,使用Gradle Android Build Tools v2.2.0,它链接到十几个预构建的.a文件,输出应该是一个.so文件。在尝试从ndk-build转换到cmake时,我无法正确地链接.so文件,因为生成的ninja构建似乎无法找到静态库的头文件。
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} )
build.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文件,但在链接时,与静态库关联的头文件似乎丢失了,导致链接失败。是否有选项告诉cmake在链接时如何找到静态库的头文件?