未定义的功能Android NDK参考

时间:2016-08-03 10:38:02

标签: android c++ opencv android-ndk

我试图用现有的使用OpenCV的c ++代码构建Android应用程序。 但Android NDK表示"未定义引用' TestMath :: getHello()' "

这是我的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();
}

最后是位于子文件夹CrossMath中的TestMath.cpp:

#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()'

2 个答案:

答案 0 :(得分:2)

.browser{ -fx-padding: 20; } 中缺少CrossMath/TestMath.cpp

除此之外,如果您在代码中引用的LOCAL_SRC_FILES应该是string,则需要在std::string中加入<string>并将类型更改为TestMath.hpp

答案 1 :(得分:0)

错误消息“未定义引用'TestMath :: getHello()'”表示NDK工具无法找到TestMath::getHello()的实现。

请尝试以下com_testapp_recognition_TestMath.cpp:

#include "TestMath.hpp"
namespace TestMath {
    string getHello() {
        return "Hello";
    }
}
#include "com_testapp_recognition_TestMath.hpp"
    JNIEXPORT jint JNICALL Java_com_testapp_recognition_TestMath_recognize(JNIEnv *, jobject, cv::Mat& originalImage) {
    return TestMath::getHello().size();
}