OpenCV - undefined reference to 'cv::CascadeClassifier::detectMultiScale() after NDK update

后端 未结 5 1322

Yesterday I updated my Android Studio included NDK to version 17.0.4754217and since then I can\'t run my app anymore. When I tried to rerun the code after the u

5条回答
  •  醉酒成梦
    2021-01-06 07:17

    A more complete answer for all the seekers out there. Using OpenCV prebuilt static libraries in your project with a native component.

    This is what I have for the build.gradle:

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 21
        externalNativeBuild {
            cmake {
                cppFlags "-fexceptions -std=gnu++11"
                arguments '-DANDROID_STL=gnustl_static'
            }
        }
        ndk {
            // Specifies the ABI configurations of your native
            // libraries Gradle should build and package with your APK.
            abiFilters 'armeabi-v7a', 'x86'
            stl = "gnustl_shared"
        }
    }
    

    This is the CMakeLists.txt:

    set(OPENCV_LIBRARIES ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libopencv_video.a
                         ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libopencv_imgproc.a
                         ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libopencv_core.a
                         ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libopencv_highgui.a
                         ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libtbb.a
                         ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libcpufeatures.a
                         )
    
    if (${ANDROID_ABI} STREQUAL "x86")
        set(OPENCV_LIBRARIES ${OPENCV_LIBRARIES}
                             ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libippiw.a
                             ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libippicv.a
                             ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libittnotify.a
                             )
        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a")
    endif()
    
    if (${ANDROID_ABI} STREQUAL "armeabi-v7a")
        set(OPENCV_LIBRARIES ${OPENCV_LIBRARIES}
                             ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/libtegra_hal.a
                             )
    endif()
    

    (then use ${OPENCV_LIBRARIES} for your target_link_libraries)

提交回复
热议问题