JNI中的cv :: FileStorage出错

时间:2015-06-18 15:36:54

标签: android c++ opencv android-ndk file-storage

我在Eclipse ADT / NDK中编译native.cpp文件时遇到错误。

编译以下代码行时

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

错误是

  

d:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o:   在功能上   Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(_JNIEnv*, _jobject*, long long, _jstring*)': D:\androidworkspace\Augmented-Reality/jni/native.cpp:14: undefined reference to cv :: FileStorage :: FileStorage(std :: string const&amp;,int,   std :: string const&amp;)'   d:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o:   在函数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 to cv :: operator&lt;&lt;(cv :: FileStorage&amp;,std :: string   常量&安培)”   d:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o:   在函数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 to cv :: write(cv :: FileStorage&amp;,std :: string   const&amp;,cv :: Mat const&amp;)'   d:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o:   在功能上   Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(_JNIEnv*, _jobject*, long long, _jstring*)': D:\androidworkspace\Augmented-Reality/jni/native.cpp:16: undefined reference to CV :: FileStorage ::释放()”   D:\ androidworkspace \ Augmented-Reality / jni / native.cpp:18:undefined   引用cv::FileStorage::~FileStorage()' D:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o: In function运算符&lt;&lt; “:   d:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2913:   未定义的引用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 to cv :: error(cv :: Exception const&amp;)'   d:/android-development/OpenCV-2.4.10-android-sdk/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/operations.hpp:2913:   未定义引用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 to cv :: Exception :: ~Exception()'   d:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/objs/ndksetup/native.o:   在功能上   Java_com_shahrukh_AugmentedReality_CAMShiftDetection_savemat(_JNIEnv*, _jobject*, long long, _jstring*)': D:\androidworkspace\Augmented-Reality/jni/native.cpp:18: undefined reference to cv :: FileStorage :: ~FileStorage()'collect2.exe:错误:ld   返回1退出状态make.exe:***   [d:/androidworkspace/Augmented-Reality//obj/local/arm64-v8a/libndksetup.so]   错误1

这是我的native.cpp文件

#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);
}

这是我的Android.mk文件

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)  

这是我的Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all

1 个答案:

答案 0 :(得分:0)

经过大量调试后我发现错误很小

错误在行

LOCAL_LDLIBS := -llog -ldl

该行应该是

LOCAL_LDLIBS += -llog -ldl