未定义对Android NDK功能的引用
Undefined reference to function 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_testap_agnition_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_testap_agnition_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()'
您的LOCAL_SRC_FILES
中缺少CrossMath/TestMath.cpp
。
除此之外,如果您在代码中引用的string
应该是std::string
,则需要在TestMath.hpp
中包含<string>
,并将类型更改为std::string
。
错误消息"对'TestMath::getHello()'的未定义引用"表示NDK工具找不到TestMath::getHello()
的实现。
请尝试以下com_testap_activation_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();
}
相关文章:
- Qt中来自不同功能的按钮引用
- 引用 using 声明引入的功能的句子是什么意思?
- 警告#13212:引用需要堆栈对齐功能的EBX
- 我的模板功能具有通用引用不起作用
- C 使用多个lambdas/绑定以引用相同的功能
- FFMPEG关于多个功能的未定义引用
- 有没有办法在我的通用功能路由器设计中支持"常量引用"作为功能签名参数?
- 对我的功能的未定义引用
- 为什么功能程序的规律性允许按值传递和按常量引用传递?
- 未定义的引用指针的变量模板在clang中功能,而不是GCC
- IFDEF块内部对功能的未定义引用
- 对完整模板专业类成员功能的未定义引用,但不是部分专业化
- 对函数的未定义引用,该功能是另一个类的成员
- 呼叫功能的值,该功能通过引用C 中的指针
- 可以接受未知签名的可变功能引用的类
- 必须调用对非静态功能的引用
- C 通过引用DLL中的功能传递std ::字符串
- 为什么BOOST.RANGE RANGE_BEGIN/END FREE功能对const和非const引用都重载
- 模板功能:混合逐个复制传递和按引用传递
- 使用mingw对魔鬼功能的未定义引用