我试图用现有的使用OpenCV的C++代码来构建Android应用程序。 但是Android NDK说: “未定义的引用 'TestMath :: getHello()'”未定义的函数Android NDK
这里是我的Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT := /mypath/OpenCV-android-sdk
OPENCV_CAMERA_MODULES := off
OPENCV_INSTALL_MODULES := off
OPENCV_LIB_TYPE := SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := CrossMath
LOCAL_SRC_FILES := com_testapp_recognition_TestMath.cpp
LOCAL_SHARED_LIBRARIES := -lopencv_java3
include $(BUILD_SHARED_LIBRARY)
Application.mk:
APP_ABI := all
APP_CPPFLAGS := -frtti -fexceptions -std=c++11
APP_STL := gnustl_static
APP_PLATFORM := android-16
com_testapp_recognition_TestMath。 hpp:
#include <jni.h>
#include "CrossMath/TestMath.hpp"
#ifndef _Included_com_testapp_recognition_TestMath
#define _Included_com_testapp_recognition_TestMath
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_com_testapp_recognition_TestMath_recognize(JNIEnv *, jobject, cv::Mat& originalImage);
#ifdef __cplusplus
}
#endif
#endif
com_testapp_recognition_TestMath.cpp:
#include "com_testapp_recognition_TestMath.hpp"
JNIEXPORT jint JNICALL Java_com_testapp_recognition_TestMath_recognize(JNIEnv *, jobject, cv::Mat& originalImage) {
return TestMath::getHello().size();
}
最后TestMath.cpp其位于子文件夹CrossMath:
#include "TestMath.hpp"
namespace TestMath {
string getHello() {
return "Hello";
}
}
TestMath.hpp:
#ifndef TestMath_hpp
#define TestMath_hpp
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core_c.h"
#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"
namespace TestMath {
string getHello();
}
Java类和定义,我检查路径和包括文件的其他人员。
错误:
Error:(13) undefined reference to `TestMath::getHello()'
请添加完整且准确的错误信息。我真的不明白'CrossMath/TestMath.hpp'的重点。函数实现不应该放在头文件中。 – Michael
@Michael显然是错字... –
字符串应该是什么? '的std :: string'?如果是这样,你在哪里包括'',以及你在哪里声明你希望它是来自'std'命名空间的'string'? –
Michael