我正在尝试在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} )
我该如何解决这个问题?感谢您的贡献。 最诚挚的问候,
答案 0 :(得分:0)
您应该声明 native-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为您定义日志库。