Reputation: 21
I have a C++
(ImageExtraction.cpp
) file which uses OpenCV
. Here is the snapshot of C++
file. I want to call this native C++ file from my Android java file. I am using Mac...
#include < string.h>
#include < jni.h>
#include < opencv2/imgproc/imgproc.hpp>
#include < opencv2/highgui/highgui.hpp>
#include < iostream>
#include < cv.h>
#include < stdio.h>
#include < algorithm>
#include < functional>
using namespace cv;
using namespace std;
extern "C"
{
JNIEXPORT jint JNICALL Java_com_clematistech_businesscardreader_BusinessCardReader_stringFromJNI(JNIEnv *env, jobject obj)
{
........
}
}
Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDES := /usr/local/include/opencv
include $(CLEAR_VARS)
include /Users/sritomamajumder/Documents/MISC/Softwares/OpenCV_for_Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ImageExtraction
LOCAL_SRC_FILES := ImageExtraction.cpp
LOCAL_STATIC_LIBRARIES := libzip libpng libjpeg freetype
LOCAL_STATIC_LIBRARIES += libopencv_contrib libopencv_legacy libopencv_ml libopencv_stitching libopencv_nonfree libopencv_objdetect libopencv_videostab libopencv_calib3d libopencv_photo libopencv_video libopencv_features2d libopencv_highgui libopencv_androidcamera libopencv_flann libopencv_imgproc libopencv_ts libopencv_core
include $(BUILD_SHARED_LIBRARY)
Here is the Application.mk:
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
APP_PLATFORM := android-10
APP_MODULES := ImageExtraction
When I ran ndk-build command from my root Android project I am getting the following errors:
[arm64-v8a] Compile++ : ImageExtraction <= ImageExtraction.cpp
[arm64-v8a] SharedLibrary : libImageExtraction.so
./obj/local/arm64-v8a/objs/ImageExtraction/ImageExtraction.o: In function `cv::Mat::~Mat()':
/Users/sritomamajumder/Documents/MISC/Softwares/OpenCV_for_Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
......
Please let me know what I have done wrong.
Upvotes: 1
Views: 1643
Reputation: 14463
with APP_ABI set to all, the latest NDKs is set to compile your code for all 64bit platforms (arm64-v8a, x86_64...) as well as the 32bit ones. But your OpenCV package doesn't contain binaries for 64bit platforms, I guess that's why you're experiencing the current issue.
You can set APP_ABI to all32
inside your Application.mk file to target only 32bit platforms (armeabi-v7a x86 armeabi mips) for which the OpenCV package is providing prebuilts for.
Upvotes: 2