我正在使用 opencv C++ 代码,以便我可以更改一些代码内容并编译它并获得结果。问题是我能够在我的 JNI 接口函数中使用 opencv c++ 的函数。在代码顶部添加标头后,我可以使用这些函数。当我运行编译时,我收到未定义的引用错误。
我这样做是为了 android 编码。
错误如下(错误很少):
Volumes/MAC/Farrakh/Software-Setups/android-ndk-r10c/toolchains/arm-linux-androideabi-
4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-
androideabi/bin/ld: ./obj/local/armeabi/objs/opencvtest/native.o: in function
cv::Mat::release():jni/opencv2/core/mat.hpp:366: error: undefined reference to
'cv::Mat::deallocate()'
/Volumes/MAC/Farrakh/Software-Setups/android-ndk-r10c/toolchains/arm-linux-androideabi-
4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-
androideabi/bin/ld: ./obj/local/armeabi/objs/opencvtest/native.o: in function
Java_com_whizpool_opencvtest_MainActivity_imread_11:jni/native.cpp:14: error: undefined reference
to 'cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&,
int)'
/Volumes/MAC/Farrakh/Software-Setups/android-ndk-r10c/toolchains/arm-linux-androideabi-
4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-
androideabi/bin/ld: ./obj/local/armeabi/objs/opencvtest/native.o: in function
Java_com_whizpool_opencvtest_MainActivity_imread_11:jni/opencv2/core/mat.hpp:277: error:
undefined reference to 'cv::fastFree(void*)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libopencvtest.so] Error 1
我尝试了很多从谷歌得到的东西,但我没有得到任何结果。
下面是用于调用 Opencv C++ 代码的 JNI 代码。
#include "com_whizpool_opencvtest_MainActivity.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
extern "C"
{
JNIEXPORT jlong JNICALL Java_com_whizpool_opencvtest_MainActivity_imread_11(JNIEnv *env, jclass obj, jstring string)
{
const char *w_buf = env->GetStringUTFChars(string, 0);
Mat imgMat = imread("abc", 0);
return 0;
}
}