Error for cv::FileStorage in JNI

asked 2015-06-18 13:15:21 -0600

I am getting errors while compiling my native.cpp file in Eclipse ADT/NDK.

While compiling the following lines of code

FileStorage storage(nativepath, FileStorage::WRITE);
storage << "img" << mat;
storage.release();

The errors are

D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In function Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(_JNIEnv*, _jobject*, long long, _jstring*)': D:\androidworkspace\Augmented-Reality/jni/native.cpp:14: undefined reference tocv::FileStorage::FileStorage(std::string const&, int, std::string const&)' D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In function operator<<': D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2923: undefined reference tocv::operator<<(cv::FileStorage&, std::string const&)' D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In function operator<< <cv::Mat>': D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2914: undefined reference tocv::write(cv::FileStorage&, std::string const&, cv::Mat const&)' D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In function Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(_JNIEnv*, _jobject*, long long, _jstring*)': D:\androidworkspace\Augmented-Reality/jni/native.cpp:16: undefined reference tocv::FileStorage::release()' D:\androidworkspace\Augmented-Reality/jni/native.cpp:18: undefined reference to cv::FileStorage::~FileStorage()' D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In functionoperator<< <cv::mat>': D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2913: undefined reference to cv::Exception::Exception(int, std::string const&, std::string const&, std::string const&, int)' D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2913: undefined reference tocv::error(cv::Exception const&)' D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2913: undefined reference to cv::Exception::~Exception()' D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2913: undefined reference tocv::Exception::~Exception()' D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In function Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(_JNIEnv*, _jobject*, long long, _jstring*)': D:\androidworkspace\Augmented-Reality/jni/native.cpp:18: undefined reference tocv::FileStorage::~FileStorage()' collect2.exe: error: ld returned 1 exit status make.exe: * [D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/libndksetup.so] Error 1

This is my native.cpp file

#include <jni.h>
#include <stdio.h>
#include <string.h>
#include <android/log.h>
#include <opencv2/core/core.hpp>

using namespace cv;

JNIEXPORT void Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(JNIEnv *env, jobject obj,jlong addrmat, jstring path)
{
    const char *nativepath = env->GetStringUTFChars(path, 0);
    Mat& mat = *(Mat*)addrmat;

    FileStorage storage(nativepath, FileStorage::WRITE);
    storage << "img" << mat;
    storage.release();

    env->ReleaseStringUTFChars(path, nativepath);
}

This is my Android.mk File

LOCAL_PATH := $(call my-dir)

export OPENCV_PACKAGE_DIR = D:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni

include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=off
include $(OPENCV_PACKAGE_DIR)/OpenCV.mk

LOCAL_LDLIBS := -llog -ldl

LOCAL_MODULE    := ndksetup
LOCAL_SRC_FILES := native.cpp

include $(BUILD_SHARED_LIBRARY)

This is my Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
edit retag flag offensive close merge delete

Comments

sorry for not knowing anything about android native development, but all errors are due to not linking the opencv_core library

berak gravatar imageberak ( 2015-06-18 13:19:29 -0600 )edit

checking it

darshan1810 gravatar imagedarshan1810 ( 2015-06-18 13:27:59 -0600 )edit