【问题标题】:OpenCV Android implementation with CMAKE undefined reference to 'cv::fastFree(void*) ErrorCMAKE未定义引用'cv :: fastFree(void *)错误的OpenCV Android实现
【发布时间】:2018-10-03 12:51:54
【问题描述】:

我正在尝试在 Android 中使用 CMAKE 实现 OpenCV310。我一起使用 dlib 库和 OpenCV 库。 Example project github link

在这个 github 链接中,它在 Android NDK 的 dlib 库中调用 opencv 方法。我正在尝试用 CMAKE 自己实现这个项目。我尝试从一个简单的 native-lib.cpp 文件调用 openCV。及其工作。但是当我添加它开始的 dlib 时会出现错误。

Error:(571) undefined reference to 'cv::fastFree(void*)'
Error:(682) undefined reference to 'cv::Mat::deallocate()'

这是我的 CMAKE 文件。

cmake_minimum_required(VERSION 3.4.1)


set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

set(pathToProject C:/Users/lenovo/AndroidStudioProjects/AdviserOpenCV3)
set(pathToOpenCV C:/Users/lenovo/Desktop/openCV310/OpenCV-3.1.0-android-sdk/OpenCV-android-sdk)

set(JNI_DETECTION_INCLUDE src/main/jni/jni_detections)
set(JNI_DETECTION_SRC src/main/jni/jni_detections)
set(JNI_COMMON_INCLUDE src/main/jni)
set(JNI_COMMON_SRC src/main/jni/jni_common)
set(DLIB_DIR src/main/dlib)
set(EXT_DIR src/main/third_party)

include_directories(${pathToOpenCV}/sdk/native/jni/include)
#include_directories(${DLIB_DIR}  ${JNI_COMMON_INCLUDE} ${JNI_DETECTION_INCLUDE} include)

add_library( lib_opencv SHARED IMPORTED)

set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION
                      ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)

add_library(android_dlib SHARED
            ${JNI_DETECTION_SRC}/jni_face_det.cpp
            ${JNI_DETECTION_SRC}/jni_imageutils.cpp
            ${JNI_DETECTION_SRC}/jni_pedestrian_det.cpp
            ${JNI_COMMON_SRC}/jni_bitmap2mat.cpp
            ${JNI_COMMON_SRC}/jni_fileutils.cpp
            ${JNI_COMMON_SRC}/jni_utils.cpp
            ${JNI_COMMON_SRC}/rgb2yuv.cpp
            ${JNI_COMMON_SRC}/yuv2rgb.cpp
            ${DLIB_DIR}/threads/threads_kernel_shared.cpp
            ${DLIB_DIR}/entropy_decoder/entropy_decoder_kernel_2.cpp
            ${DLIB_DIR}/base64/base64_kernel_1.cpp
            ${DLIB_DIR}/threads/threads_kernel_1.cpp
            ${DLIB_DIR}/threads/threads_kernel_2.cpp
            ${EXT_DIR}/glog/logging.cc)


add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                   android_dlib
                   lib_opencv
                   # Links the target library to the log library
                   # included in the NDK.
                   $\{log-lib} )

我该如何解决这个问题?感谢你的贡献。 最好的问候,

【问题讨论】:

  • 你可以从${pathToOpenCV}/sdk/native/libs/${ANDROID_ABI}/libopencv_java3.so中选择libopencv_java3.so文件,不需要复制到jniLibs
  • 如果你在native-lib库中使用OpenCV函数,那么你应该用lib_opencv链接给定的库。但是你链接android_dlib一个。

标签: android opencv cmake android-ndk dlib


【解决方案1】:

您应该声明 native-liblib_opencv 之间的依赖关系。你可能也想要 android_dlib

target_link_libraries(
    native-lib
    android_dlib
    lib_opencv
   # Links the target library to the log library
   # included in the NDK.
    log )

正如您在上面看到的,您的脚本中不需要 ${log-lib}; Android NDK 为您定义了 log 库。

【讨论】:

  • android_dlib 的源文件之一是${EXT_DIR}/glog/logging.cc。我猜,这个文件使用了日志功能,所以android_dlib 本身应该与log 链接:target_link_libraries(android_dlib log)
猜你喜欢
  • 1970-01-01
  • 2015-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 2016-06-26
  • 1970-01-01
相关资源
最近更新 更多