I'm trying to create a static library that takes an image, do some image processing using OpenCV and finally return a string. I decide to use my own static library to use in android platform. First of all, I build OpenCV for the android platform (or just download OpenCV SDK for android). So I have both shared and static library of OpenCV. after that, I tried to build my own library that uses these OpenCV modules: core, imgproc, dnn
and finally, I had .a file with 1.2 MB of size. but when I added my library to android I got compiled error :
undefined reference to 'cv::Sobel(cv::_InputArray const&, cv::_OutputArray const&, int, int, int, int, double, double, int)'
It seems that my library did not include OpenCV modules. I was searching a lot about this issue but I got nothing and almost try everything. Here is cmakeList.txt for my library :
if (" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "FATAL: In-source builds are not allowed.
You should create a separate directory for build files.")
endif ()
cmake_minimum_required(VERSION 3.14)
project(scanner)
set(CMAKE_CXX_STANDARD 14)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR/lib})
set(SCANNER_LIBRARY_SOURCES business/ImageProcessor.cpp
util/ContoursUtil.cpp
Predictor.cpp)
add_library(scanner STATIC ${SCANNER_LIBRARY_SOURCES})
include_directories(/Users/shayantabatabaei/Downloads/sdk/sdk/native/jni/include)
target_link_libraries(scanner INTERFACE
/Users/shayantabatabaei/Downloads/sdk/sdk/native/staticlibs/x86/libopencv_core.a
/Users/shayantabatabaei/Downloads/sdk/sdk/native/staticlibs/x86/libopencv_dnn.a
/Users/shayantabatabaei/Downloads/sdk/sdk/native/staticlibs/x86/libopencv_imgproc.a)
install(FILES Predictor.h
DESTINATION ${CMAKE_BINARY_DIR}/include)
and I build my library whit this command :
cmake .. -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_NDK=$ANDROID_NDK -DANDROID_NATIVE_API_LEVEL=android-28 -DANDROID_STL=c++_static -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX:PATH=$(pwd) -DANDROID_ABI=${TARGET};
thanks.