I'm trying to use opencv native library in an android studio project. I get an error for undefined reference for the function knnMatch.
I have added openCVLibrary to my project and had success to use other openCV features.
UPDATE: Add my compiling files
My App 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
}
My 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 )
In my jniLibs -> arm64-v8a
I have those 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
As I said other cv function like cv::solvePnP
work fine.
only KnnMatch
throw undifined.
UPDATE: If I'm remove -DANDROID_STL=c++_shared
I can compile knnMatch
but I need it, any suggestions?
Hi It is clearly a linking error. While compiling your code, method you are referring from external library could not be included or linked. During compilation a linker look for reference to that method in all libraries and if it could not find that method definition in the libraries or obj files it gives you this error. If you are using a make file check whether you have properly added the required library in it. Also check whether library has been set to the path environment variable or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With