OpenCV未定义的参考

时间:2014-11-17 06:20:07

标签: opencv opencv4android opencv3.0

我正在使用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;
}
}

1 个答案:

答案 0 :(得分:1)

您的错误是链接器错误;你需要告诉链接器链接opencv_core和opencv_highgui。您可以在makefile或为您创建makefile的构建系统中执行此操作(如果有)。