问题描述
按照Google Android.mk转换为CMakeLists.txt
的过程/main/cpp/CMakeLists.txt"rel =" noreferrer> hello-libs示例,我遇到了避免未定义引用的问题.我正在使用一个名为 DCMTK 的开源项目,并编译DCMTK和 ICONV 到我随后链接的静态库.使用Android.mk
进行构建可通过ndk-build
进行,并使用gradle
和以下当我将每个静态库添加到target_link_libraries
时,>均有效.但是,我想使用add_library
来完成工作并尝试
In converting a library project build from Android.mk
to CMakeLists.txt
following the Google hello-libs example and I have encountered problems avoiding undefined references. I'm using an open source project called DCMTK and compiling DCMTK and ICONV to static libraries that I then link in. Building using the Android.mk
works via ndk-build
and building them with gradle
and the following CMakeLists.txt
works when I add each static library to the target_link_libraries
. However, I wanted to use add_library
to do the job and tried
add_library( lib_dcmdata STATIC IMPORTED )
set_target_properties( lib_dcmdata
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdata.a )
每个库,然后将它们添加到target_link_libraries.这导致大量未定义的引用.我还通过将静态库分组到一个目标中来尝试set_target_properties,但这也不起作用.
for each library and then adding them to target_link_libraries. This resulted in a ton of undefined references. I also tried set_target_properties by grouping the static libraries into one target, but this didn't work either.
依赖关系链接的顺序是否有所不同,或者CMake使用add_library
set_target_properties
方法处理这些库的方式不同?
Is the order of dependency linking different in some way or the way CMake handles these libraries different using the add_library
set_target_properties
method?
cmake_minimum_required( VERSION 3.6 )
project( dicom-jni )
set( SOURCE_FILES
dicom.cpp
dicom.hpp )
add_library( lib_dcmtk STATIC IMPORTED )
set_target_properties( lib_dcmtk
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmrt.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmpstat.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmqrdb.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmwlm.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdsig.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmnet.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmjpeg.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmjpls.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libcharls.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg16.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg12.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg8.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmimage.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmimgle.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libi2d.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdata.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/liboflog.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libofstd.a )
add_library( lib_iconv STATIC IMPORTED )
set_target_properties( lib_iconv
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/iconv/${ANDROID_ABI}/lib/libiconv.a
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/iconv/${ANDROID_ABI}/lib/libcharset.a )
find_library( lib_jnigraphics jnigraphics )
find_library( lib_android-log log )
add_library( dicom-jni SHARED ${SOURCE_FILES} )
target_include_directories( dicom-jni PRIVATE
prebuilt_libs/dcmtk/${ANDROID_ABI}/include
prebuilt_libs/iconv/${ANDROID_ABI}/include
logger )
target_link_libraries( dicom-jni
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmrt.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmpstat.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmqrdb.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmwlm.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdsig.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmnet.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmjpeg.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmjpls.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libcharls.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg16.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg12.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg8.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmimage.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmimgle.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libi2d.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdata.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/liboflog.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libofstd.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/iconv/${ANDROID_ABI}/lib/libiconv.a
${CMAKE_SOURCE_DIR}/prebuilt_libs/iconv/${ANDROID_ABI}/lib/libcharset.a
z
dl
stdc++
${lib_jnigraphics}
${lib_android-log} )
推荐答案
虽然我不确定是否将所有静态库的IMPORTED_LOCATION添加到整体上,但将工作依赖顺序分解为库确实可行.
While I'm unsure about adding the IMPORTED_LOCATION of all the static libraries en masse breaking the work dependency order into libraries does work.
cmake_minimum_required( VERSION 3.6 )
project( dicom-jni )
set( SOURCE_FILES
dicom.cpp
dicom.hpp )
add_library( lib_dcmrt STATIC IMPORTED )
set_target_properties( lib_dcmrt
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmrt.a )
add_library( lib_dcmpstat STATIC IMPORTED )
set_target_properties( lib_dcmpstat
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmpstat.a )
add_library( lib_dcmqrdb STATIC IMPORTED )
set_target_properties( lib_dcmqrdb
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmqrdb.a )
add_library( lib_dcmwlm STATIC IMPORTED )
set_target_properties( lib_dcmwlm
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmwlm.a )
add_library( lib_dcmdsig STATIC IMPORTED )
set_target_properties( lib_dcmdsig
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdsig.a )
add_library( lib_dcmnet STATIC IMPORTED )
set_target_properties( lib_dcmnet
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmnet.a )
add_library( lib_dcmjpeg STATIC IMPORTED )
set_target_properties( lib_dcmjpeg
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmjpeg.a )
add_library( lib_dcmjpls STATIC IMPORTED )
set_target_properties( lib_dcmjpls
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmjpls.a )
add_library( lib_charls STATIC IMPORTED )
set_target_properties( lib_charls
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libcharls.a )
add_library( lib_ijg16 STATIC IMPORTED )
set_target_properties( lib_ijg16
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg16.a )
add_library( lib_ijg12 STATIC IMPORTED )
set_target_properties( lib_ijg12
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg12.a )
add_library( lib_ijg8 STATIC IMPORTED )
set_target_properties( lib_ijg8
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libijg8.a )
add_library( lib_dcmimage STATIC IMPORTED )
set_target_properties( lib_dcmimage
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmimage.a )
add_library( lib_dcmimgle STATIC IMPORTED )
set_target_properties( lib_dcmimgle
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmimgle.a )
add_library( lib_i2d STATIC IMPORTED )
set_target_properties( lib_i2d
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libi2d.a )
add_library( lib_dcmdata STATIC IMPORTED )
set_target_properties( lib_dcmdata
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libdcmdata.a )
add_library( lib_oflog STATIC IMPORTED )
set_target_properties( lib_oflog
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/liboflog.a )
add_library( lib_ofstd STATIC IMPORTED )
set_target_properties( lib_ofstd
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/dcmtk/${ANDROID_ABI}/lib/libofstd.a )
add_library( lib_iconv STATIC IMPORTED )
set_target_properties( lib_iconv
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/iconv/${ANDROID_ABI}/lib/libiconv.a )
add_library( lib_charset STATIC IMPORTED )
set_target_properties( lib_charset
PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/iconv/${ANDROID_ABI}/lib/libcharset.a )
find_library( lib_jnigraphics jnigraphics )
find_library( lib_android-log log )
add_library( dicom-jni SHARED ${SOURCE_FILES} )
target_include_directories( dicom-jni PRIVATE
prebuilt_libs/dcmtk/${ANDROID_ABI}/include
prebuilt_libs/iconv/${ANDROID_ABI}/include
logger )
target_link_libraries( dicom-jni
lib_dcmrt
lib_dcmpstat
lib_dcmqrdb
lib_dcmwlm
lib_dcmdsig
lib_dcmnet
lib_dcmjpeg
lib_dcmjpls
lib_charls
lib_ijg16
lib_ijg12
lib_ijg8
lib_dcmimage
lib_dcmimgle
lib_i2d
lib_dcmdata
lib_oflog
lib_ofstd
lib_iconv
lib_charset
z
dl
stdc++
${lib_jnigraphics}
${lib_android-log} )
这篇关于Android,CMake和静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!