将本机库链接到Android项目

时间:2017-05-23 12:50:33

标签: android android-ndk cmake linker java-native-interface

我想在我的Android Studio项目中使用用C语言编写的CCV library。我设法编译它,但我认为我现在面临一些链接错误,因为我的包装器中存在这些错误:

C:\Users\henry\Documents\android-project\app\src\main\jni\ccv\ccv.cpp
   Error:(25) undefined reference to `ccv_read_impl(void const*, ccv_dense_matrix_t**, int, int, int, int)'
Error:error: linker command failed with exit code 1 (use -v to see invocation)

这是我的CMakeLists文件的样子:

cmake_minimum_required(VERSION 3.4.1)

#This is my wrapper
add_library( ccv SHARED
             src/main/jni/ccv/ccv.cpp
           )

#This is the actual library
add_library( ccvlib SHARED
             src/main/jni/ccv/lib/3rdparty/dsfmt/dSFMT.c
             src/main/jni/ccv/lib/3rdparty/dsfmt/dSFMT.h
             src/main/jni/ccv/lib/3rdparty/dsfmt/dSFMT-common.h
             src/main/jni/ccv/lib/3rdparty/dsfmt/dSFMT-params.h
             src/main/jni/ccv/lib/3rdparty/dsfmt/dSFMT-params19937.h
             src/main/jni/ccv/lib/3rdparty/kissfft/_kiss_fft_guts.h
             src/main/jni/ccv/lib/3rdparty/kissfft/_kissf_fft_guts.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fft.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fft.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fftnd.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fftnd.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fftndr.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fftndr.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fftr.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kiss_fftr.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fft.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fft.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fftnd.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fftnd.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fftndr.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fftndr.h
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fftr.c
             src/main/jni/ccv/lib/3rdparty/kissfft/kissf_fftr.h
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT.c
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT.h
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT-alti.h
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT-common.h
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT-params.h
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT-params19937.h
             src/main/jni/ccv/lib/3rdparty/sfmt/SFMT-sse2.h
             src/main/jni/ccv/lib/3rdparty/sha1/sha1.c
             src/main/jni/ccv/lib/3rdparty/sha1/sha1.h
#            src/main/jni/ccv/lib/3rdparty/sqlite3/sqlite3.c
#            src/main/jni/ccv/lib/3rdparty/sqlite3/sqlite3.h
#            src/main/jni/ccv/lib/inl/ccv_convnet_inl.h
             src/main/jni/ccv/lib/io/_ccv_io_binary.c
#            src/main/jni/ccv/lib/io/_ccv_io_bmp.c
#            src/main/jni/ccv/lib/io/_ccv_io_libjpeg.c
#            src/main/jni/ccv/lib/io/_ccv_io_libpng.c
             src/main/jni/ccv/lib/io/_ccv_io_raw.c
             src/main/jni/ccv/lib/ccv.h
             src/main/jni/ccv/lib/ccv_algebra.c
             src/main/jni/ccv/lib/ccv_basic.c
             src/main/jni/ccv/lib/ccv_bbf.c
             src/main/jni/ccv/lib/ccv_cache.c
             src/main/jni/ccv/lib/ccv_classic.c
#            src/main/jni/ccv/lib/ccv_convnet.c
             src/main/jni/ccv/lib/ccv_daisy.c
             src/main/jni/ccv/lib/ccv_doxygen.h
#            src/main/jni/ccv/lib/ccv_dpm.c
             src/main/jni/ccv/lib/ccv_ferns.c
             src/main/jni/ccv/lib/ccv_icf.c
             src/main/jni/ccv/lib/ccv_image_processing.c
             src/main/jni/ccv/lib/ccv_internal.h
             src/main/jni/ccv/lib/ccv_io.c
             src/main/jni/ccv/lib/ccv_memory.c
             src/main/jni/ccv/lib/ccv_mser.c
#            src/main/jni/ccv/lib/ccv_numeric.c
             src/main/jni/ccv/lib/ccv_output.c
             src/main/jni/ccv/lib/ccv_resample.c
#            src/main/jni/ccv/lib/ccv_scd.c
             src/main/jni/ccv/lib/ccv_sift.c
             src/main/jni/ccv/lib/ccv_sparse_coding.c
             src/main/jni/ccv/lib/ccv_swt.c
             src/main/jni/ccv/lib/ccv_tld.c
             src/main/jni/ccv/lib/ccv_transform.c
             src/main/jni/ccv/lib/ccv_util.c
           )

target_link_libraries( ccv
                       ccvlib
                       log
                       android
                     )

1 个答案:

答案 0 :(得分:0)

好吧,它实际上不是链接器错误:由于CCV是一个C库,我必须将它作为C代码包含在我的包装器中:

extern "C" {
#include "lib/ccv.h"
};