围绕调用方法编写C ++方法

时间:2016-01-15 00:11:25

标签: android c++ android-ndk java-native-interface

我遇到了围绕调用方法编写包装器的问题。这是我的包装器:

#include <jni.h>
#include <cassert>
#include <fstream>
#include "TextDetection.h"
#include <opencv/highgui.h>
#include <exception>

extern "C" {


   JNIEXPORT int JNICALL Java_cgi_pi_detect() {

   IplImage * byteQueryImage = loadByteImage ( "Image_utilisateur.png" );
  if ( !byteQueryImage )
  {
    printf ( "couldn't load query image\n" );
    return -1;
  }

  // Detect text in the image
  IplImage * output = textDetection ( byteQueryImage, atoi(1));
  cvReleaseImage ( &byteQueryImage );
  cvSaveImage ( "Image_Tesseract.png", output );
  cvReleaseImage ( &output );
  return 0;
}
}

但是当我尝试使用Android.mk编译包装器时,我收到了错误:

    [armeabi] Compile++ thumb: wrapper <= wrapper.cpp
[armeabi] SharedLibrary  : libwrapper.so
jni/wrapper.cpp:22: error: undefined reference to 'cvReleaseImage'
jni/wrapper.cpp:23: error: undefined reference to 'cvSaveImage'
jni/wrapper.cpp:24: error: undefined reference to 'cvReleaseImage'
jni/FeaturesMain.cpp:29: error: undefined reference to 'cvConvertScale'
jni/FeaturesMain.cpp:50: error: undefined reference to 'cvLoadImage'
jni/FeaturesMain.cpp:56: error: undefined reference to 'cvCvtColor'
jni/FeaturesMain.cpp:62: error: undefined reference to 'cvLoadImage'
jni/FeaturesMain.cpp:68: error: undefined reference to 'cvCvtColor'
jni/FeaturesMain.cpp:70: error: undefined reference to 'cvGetSize'
jni/FeaturesMain.cpp:70: error: undefined reference to 'cvCreateImage'
jni/FeaturesMain.cpp:71: error: undefined reference to 'cvConvertScale'
jni/FeaturesMain.cpp:72: error: undefined reference to 'cvReleaseImage'
jni/FeaturesMain.cpp:87: error: undefined reference to 'cvReleaseImage'
jni/FeaturesMain.cpp:88: error: undefined reference to 'cvSaveImage'
jni/TextDetection.cpp:132: error: undefined reference to 'cvSetZero'
jni/TextDetection.cpp:178: error: undefined reference to 'cvGetSize'
jni/TextDetection.cpp:178: error: undefined reference to 'cvCreateImage'
jni/TextDetection.cpp:191: error: undefined reference to 'cvGetSize'
jni/TextDetection.cpp:191: error: undefined reference to 'cvCreateImage'
jni/TextDetection.cpp:192: error: undefined reference to 'cvConvertScale'
jni/TextDetection.cpp:193: error: undefined reference to 'cvCvtColor'
jni/TextDetection.cpp:204: error: undefined reference to 'cvRectangle'
jni/TextDetection.cpp:231: error: undefined reference to 'cvGetSize'
jni/TextDetection.cpp:231: error: undefined reference to 'cvCreateImage'
jni/TextDetection.cpp:240: error: undefined reference to 'cvConvertScale'
jni/TextDetection.cpp:241: error: undefined reference to 'cvCvtColor'
jni/TextDetection.cpp:252: error: undefined reference to 'cvRectangle'
jni/boost/include/boost-1_53/boost/unordered/detail/unique.hpp:270: error: undefined reference to 'b
oost::throw_exception(std::exception const&)'
jni/TextDetection.cpp:299: error: undefined reference to 'cvCanny'
jni/TextDetection.cpp:300: error: undefined reference to 'cvSaveImage'
jni/TextDetection.cpp:306: error: undefined reference to 'cvSmooth'
jni/TextDetection.cpp:311: error: undefined reference to 'cvSobel'
jni/TextDetection.cpp:312: error: undefined reference to 'cvSobel'
jni/TextDetection.cpp:313: error: undefined reference to 'cvSmooth'
jni/TextDetection.cpp:314: error: undefined reference to 'cvSmooth'
jni/TextDetection.cpp:337: error: undefined reference to 'cvSaveImage'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libwrapper.so] Error 1

这些方法在我的其他C ++文件中实现。这是Android.mk:

LOCAL_PATH := $(call my-dir)

# static library info
LOCAL_MODULE := Library
LOCAL_SRC_FILES := libSWT.a
include $(PREBUILT_STATIC_LIBRARY)

# wrapper info
include $(CLEAR_VARS)
LOCAL_MODULE    := wrapper
LOCAL_C_INCLUDES := jni/opencv/include/
LOCAL_C_INCLUDES += jni/boost/include/boost-1_53
LOCAL_SRC_FILES := wrapper.cpp
LOCAL_STATIC_LIBRARIES := Library
include $(BUILD_SHARED_LIBRARY)

这就是我获取libSWT.a的方式:

LOCAL_PATH := $(call my-dir)

# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_core
LOCAL_SRC_FILES := opencv/lib/libopencv_core.a
include $(PREBUILT_STATIC_LIBRARY)

# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_highgui
LOCAL_SRC_FILES := opencv/lib/libopencv_highgui.a
include $(PREBUILT_STATIC_LIBRARY)

# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_imgproc
LOCAL_SRC_FILES := opencv/lib/libopencv_imgproc.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := SWT
LOCAL_STATIC_LIBRARIES := opencv_core \
    opencv_highgui \
    opencv_imgproc 
LOCAL_C_INCLUDES := jni/opencv/include/
LOCAL_C_INCLUDES += jni/boost/include/boost-1_53
LOCAL_SRC_FILES := FeaturesMain.cpp \
 TextDetection.cpp

include $(BUILD_STATIC_LIBRARY)

我想因为我用OpenCV和Boost编译了libSWT.a,我没有必要在Android.mk中指定它们吗?

0 个答案:

没有答案