c – 对`cv :: DescriptorMatcher :: knnMatch的未定义引用

我正在尝试在
android工作室项目中使用opencv本机库.我为函数knnMatch的未定义引用收到错误.

我已将openCVLibrary添加到我的项目中,并成功使用其他openCV功能.

>是否有具体使用libopencv_features2d的原因?
>编译和链接features2d的正确方法是什么?

更新:添加我的编译文件

我的应用build.gradle:

apply plugin: 'com.android.application'
//
android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
//
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27
        ...
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang" , "-DANDROID_STL=c++_static","-DCMAKE_BUILD_TYPE=Release", "-DANDROID_CPP_FEATURES=rtti exceptions"
                cppFlags    "-D__STDC_FORMAT_MACROS" , '-O3','-fopenmp','-fsigned-char', "-std=c++14", "-frtti", "-fexceptions", "-mfloat-abi=softfp", "-Wall"
            }
            ndk {
                abiFilters 'arm64-v8a'
            }
        }
    }
    //
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    ...
}
//
dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        implementation project(':openCVLibrary340') //Module
}

我的CMakeList.txt:

cmake_minimum_required(VERSION 3.4.1)
#
include_directories(/.../OpenCV-android-sdk/sdk/native/jni/include)
add_library( libopencv SHARED IMPORTED )
set_target_properties(libopencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
#
FILE(GLOB CPP_SRC
"src/main/cpp/*.c"
"src/main/cpp/*.h"
"src/main/cpp/*.cpp"
"src/main/cpp/*.hpp"
)
#
add_library( myLib SHARED ${CPP_SRC} )
#
find_library( log-lib log )
#
target_link_libraries( myLib libopencv ${log-lib} )
target_link_libraries( myLib android log EGL GLESv2 )

在我的jniLibs中 – > arm64-v8a我有那些cv libs:

libopencv_calib3d.a, libopencv_core.a, libopencv_dnn.a,
libopencv_features2d.a libopencv_flann.a, libopencv_highgui.a,
libopencv_imgcodecs.a, libopencv_imgproc.a, libopencv_java3.so,
libopencv_ml.a, libopencv_objdetect.a, libopencv_photo.a,
libopencv_shape.a libopencv_stitching.a, libopencv_superres.a,
libopencv_video.a, libopencv_videoio.a, libopencv_videostab.a

正如我所说的其他cv函数,如cv :: solvePnP工作正常.
只有KnnMatch扔未定型.

更新:如果我删除-DANDROID_STL = c _shared我可以编译knnMatch但我需要它,任何建议?

最佳答案 嗨这显然是一个链接错误.在编译代码时,无法包含或链接您从​​外部库引用的方法.在编译期间,链接器在所有库中查找对该方法的引用,如果它在库或obj文件中找不到该方法定义,则会给出此错误.如果您使用的是make文件,请检查是否已在其中正确添加了所需的库.还要检查库是否已设置为路径环境变量.

点赞