在Mac OSX上为OpenCV编译Android JNI

时间:2013-05-09 23:43:21

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

忍受我 - 这是一个很长的描述,但我想包括所有细节。我正在尝试使用Android NDK和JNI来构建OpenCV Android应用程序。

我正在按照本教程安装所有内容: http://www.stanford.edu/class/ee368/Android/Tutorial-2-OpenCV-for-Android-Setup-Macintosh-API8.pdf

以下安装就好了:

/usr/bin/g++
/usr/local/bin/swig
/usr/bin/cmake
/usr/bin/make
/Developer/pcre-8.32/

我的.bashrc文件的内容:

export  NDK=/Users/Me/Code/Android/android-ndk-r4-crystax
export  SDK=/Users/Me/Code/Android/adt-bundle-mac-x86_64-20130219/
export  OPCV=/Users/Me/Code/OpenCV/opencv
export  PATH=$NDK:$SDK/tools:$SDK/platform-tools:$PATH
export NDK_ROOT=$NDK

使OpenCV库变好了。

由于使用make的投诉,我不得不在/Users/Me/Code/OpenCV/opencv/android/android-jni/local.env.mk进行一次小编辑,看起来像这样:

#ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax
ANDROID_NDK_ROOT=/Users/Me/Code/Android/android-ndk-r4-crystax

然后在android-jni目录中再次尝试make时,遇到了灾难:

/Users/Me/Code/Android/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
    PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V= 
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
Gdbserver      : [arm-eabi-4.4.0] /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdbserver
Gdbsetup       : /Users/Me/Code/OpenCV/opencv/android/android-jni/libs/armeabi-v7a/gdb.setup
Gdbsetup       : + source directory /Users/Me/Code/OpenCV/opencv/android/android-jni/jni
SharedLibrary  : libandroid-opencv.so
/Users/Me/Code/Android/android-ndk-r4-crystax/build/prebuilt/darwin-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: cannot find -lopencv_calib3d
collect2: ld returned 1 exit status
make[1]: *** [/Users/Me/Code/OpenCV/opencv/android/android-jni/obj/local/armeabi/libandroid-opencv.so] Error 1
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2

我想也许这是一个pkg-config错误,但这似乎也已经设置好了,不过在我以前安装的OpenCV中。以下是pkg-config --cflags --libs opencv

的输出
-I/usr/include/opencv  /usr/lib/libopencv_calib3d.dylib /usr/lib/libopencv_contrib.dylib /usr/lib/libopencv_core.dylib /usr/lib/libopencv_features2d.dylib /usr/lib/libopencv_flann.dylib /usr/lib/libopencv_gpu.dylib /usr/lib/libopencv_highgui.dylib /usr/lib/libopencv_imgproc.dylib /usr/lib/libopencv_legacy.dylib /usr/lib/libopencv_ml.dylib /usr/lib/libopencv_nonfree.dylib /usr/lib/libopencv_objdetect.dylib /usr/lib/libopencv_photo.dylib /usr/lib/libopencv_stitching.dylib /usr/lib/libopencv_ts.dylib /usr/lib/libopencv_video.dylib /usr/lib/libopencv_videostab.dylib 

此特定教程构建的安装在此位置放置了opencv.pc文件:

/Users/Me/Code/OpenCV/opencv/build/unix-install

但是运行以下内容并再次尝试make并不能解决问题:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Users/Me/Code/OpenCV/opencv/build/unix-install

我无法弄清楚出了什么问题。我一直在和这个问题争吵大约一个月,最后需要一些外界意见。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

错误消息说

  

找不到-lopencv_calib3d collect2:ld返回1退出状态

这意味着链接器找不到opencv_calib3d库。它的名称可能是libopencv_calib3d.a或libopencv_calib3d.so。因此,您需要找到其中一个并将此文件的路径添加到LD_LIBRARY_PATH env变量。

我的意思是如果让我们说文件夹/ Users / Me / Code / OpenCV / opencv / lib包含libopencv_calib3d.so那么你需要在make之前执行类似下面的事情:

export LD_LIBRARY_PATH=/Users/Me/Code/OpenCV/opencv/lib:$LD_LIBRARY_PATH

答案 1 :(得分:0)