我正在尝试用Android中的cmake实现OpenCv310。我一起使用dlib库和openCV库。示例项目github链接
在此github链接中,其在Android NDK上的DLIB库中调用OpenCV方法。我正在尝试使用CMAKE实施该项目。我尝试从一个简单的本机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} )
我该如何解决这个问题?感谢你的贡献。最好的问候,
您应该在本机lib 和 lib_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 为您提供库。