在 Android NDK 中编译 OpenCV
请查看底部的添加内容!第一个问题在Linux下解决了,在Windows和Cygwin下还没有解决,但是又出现了一个新问题。请参阅下文!
我目前正在尝试为 Android NDK 编译 OpenCV,以便我可以在我的应用程序中使用它。为此,我尝试遵循本指南:
http://www.stanford.edu/~zxwang/ android_opencv.html
但是,当使用 ndk-build 编译下载的内容时,我收到此错误:
$ /cygdrive/u/flori/workspace/android-ndk-r5b/ndk-build
Compile++ thumb : opencv <= cvjni.cpp
Compile++ thumb : cxcore <= cxalloc.cpp
Compile++ thumb : cxcore <= cxarithm.cpp
Compile++ thumb : cxcore <= cxarray.cpp
Compile++ thumb : cxcore <= cxcmp.cpp
Compile++ thumb : cxcore <= cxconvert.cpp
Compile++ thumb : cxcore <= cxcopy.cpp
Compile++ thumb : cxcore <= cxdatastructs.cpp
Compile++ thumb : cxcore <= cxdrawing.cpp
Compile++ thumb : cxcore <= cxdxt.cpp
Compile++ thumb : cxcore <= cxerror.cpp
Compile++ thumb : cxcore <= cximage.cpp
Compile++ thumb : cxcore <= cxjacobieigens.cpp
Compile++ thumb : cxcore <= cxlogic.cpp
Compile++ thumb : cxcore <= cxlut.cpp
Compile++ thumb : cxcore <= cxmathfuncs.cpp
Compile++ thumb : cxcore <= cxmatmul.cpp
Compile++ thumb : cxcore <= cxmatrix.cpp
Compile++ thumb : cxcore <= cxmean.cpp
Compile++ thumb : cxcore <= cxmeansdv.cpp
Compile++ thumb : cxcore <= cxminmaxloc.cpp
Compile++ thumb : cxcore <= cxnorm.cpp
Compile++ thumb : cxcore <= cxouttext.cpp
Compile++ thumb : cxcore <= cxpersistence.cpp
Compile++ thumb : cxcore <= cxprecomp.cpp
Compile++ thumb : cxcore <= cxrand.cpp
Compile++ thumb : cxcore <= cxsumpixels.cpp
Compile++ thumb : cxcore <= cxsvd.cpp
Compile++ thumb : cxcore <= cxswitcher.cpp
Compile++ thumb : cxcore <= cxtables.cpp
Compile++ thumb : cxcore <= cxutils.cpp
StaticLibrary : libstdc++.a
StaticLibrary : libcxcore.a
Compile++ thumb : cv <= cvaccum.cpp
Compile++ thumb : cv <= cvadapthresh.cpp
Compile++ thumb : cv <= cvapprox.cpp
Compile++ thumb : cv <= cvcalccontrasthistogram.cpp
Compile++ thumb : cv <= cvcalcimagehomography.cpp
Compile++ thumb : cv <= cvcalibinit.cpp
Compile++ thumb : cv <= cvcalibration.cpp
Compile++ thumb : cv <= cvcamshift.cpp
Compile++ thumb : cv <= cvcanny.cpp
Compile++ thumb : cv <= cvcolor.cpp
Compile++ thumb : cv <= cvcondens.cpp
Compile++ thumb : cv <= cvcontours.cpp
Compile++ thumb : cv <= cvcontourtree.cpp
Compile++ thumb : cv <= cvconvhull.cpp
Compile++ thumb : cv <= cvcorner.cpp
Compile++ thumb : cv <= cvcornersubpix.cpp
Compile++ thumb : cv <= cvderiv.cpp
Compile++ thumb : cv <= cvdistransform.cpp
Compile++ thumb : cv <= cvdominants.cpp
Compile++ thumb : cv <= cvemd.cpp
Compile++ thumb : cv <= cvfeatureselect.cpp
Compile++ thumb : cv <= cvfilter.cpp
Compile++ thumb : cv <= cvfloodfill.cpp
Compile++ thumb : cv <= cvfundam.cpp
Compile++ thumb : cv <= cvgeometry.cpp
Compile++ thumb : cv <= cvhaar.cpp
Compile++ thumb : cv <= cvhistogram.cpp
Compile++ thumb : cv <= cvhough.cpp
Compile++ thumb : cv <= cvimgwarp.cpp
Compile++ thumb : cv <= cvinpaint.cpp
Compile++ thumb : cv <= cvkalman.cpp
Compile++ thumb : cv <= cvlinefit.cpp
Compile++ thumb : cv <= cvlkpyramid.cpp
Compile++ thumb : cv <= cvmatchcontours.cpp
Compile++ thumb : cv <= cvmoments.cpp
Compile++ thumb : cv <= cvmorph.cpp
Compile++ thumb : cv <= cvmotempl.cpp
Compile++ thumb : cv <= cvoptflowbm.cpp
Compile++ thumb : cv <= cvoptflowhs.cpp
Compile++ thumb : cv <= cvoptflowlk.cpp
Compile++ thumb : cv <= cvpgh.cpp
Compile++ thumb : cv <= cvposit.cpp
Compile++ thumb : cv <= cvprecomp.cpp
Compile++ thumb : cv <= cvpyramids.cpp
Compile++ thumb : cv <= cvpyrsegmentation.cpp
Compile++ thumb : cv <= cvrotcalipers.cpp
Compile++ thumb : cv <= cvsamplers.cpp
Compile++ thumb : cv <= cvsegmentation.cpp
Compile++ thumb : cv <= cvshapedescr.cpp
Compile++ thumb : cv <= cvsmooth.cpp
Compile++ thumb : cv <= cvsnakes.cpp
Compile++ thumb : cv <= cvstereobm.cpp
Compile++ thumb : cv <= cvstereogc.cpp
Compile++ thumb : cv <= cvsubdivision2d.cpp
Compile++ thumb : cv <= cvsumpixels.cpp
Compile++ thumb : cv <= cvsurf.cpp
Compile++ thumb : cv <= cvswitcher.cpp
Compile++ thumb : cv <= cvtables.cpp
Compile++ thumb : cv <= cvtemplmatch.cpp
Compile++ thumb : cv <= cvthresh.cpp
Compile++ thumb : cv <= cvundistort.cpp
Compile++ thumb : cv <= cvutils.cpp
StaticLibrary : libcv.a
SharedLibrary : libopencv.so
U:/flori/workspace/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebui
lt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-andr
oideabi/bin/ld.exe: cannot find -lcxcore
collect2: ld returned 1 exit status
make: *** [/cygdrive/u/flori/workspace/android/testOpenCV/obj/local/armeabi/libo
pencv.so] Error 1
我正在尝试在 Windows 系统上使用最新的 NDK 版本编译它...
有人知道这个链接错误是什么吗意味着什么,我能做什么让它再次工作?
如果有人能提供帮助,那就太好了
在解决问题后,我发现还有另一种编译 Android 版 OpenCV 的方法,使用当前版本的 OpenCV(而不是上面的 1.1 版)和来自 crystaltax 的修改后的 Android NDK,其中支持STL和异常,因此支持最新的OpenCV版本。
所有相关信息都可以在这里找到: http://opencv.willowgarage.com/wiki/Android
那里说下载当前的svn trunk 和crystax-r4 android-ndk,以及我所做的swig。
我进入该文件夹,创建构建目录,运行 cmake,然后构建静态库,这似乎有效。至少它成功地运行了 make 命令,没有错误。
我现在想要构建共享库,因此我进入 android-jni 文件夹并再次运行“make”,但收到此错误:
% make -j4
OPENCV_CONFIG = ../build/android-opencv.mk
make clean-swig &&\
mkdir -p jni/gen &&\
mkdir -p src/com/opencv/jni &&\
swig -java -c++ -package "com.opencv.jni" \
-outdir src/com/opencv/jni \
-o jni/gen/android_cv_wrap.cpp jni/android-cv.i
OPENCV_CONFIG = ../build/android-opencv.mk
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
rm -f jni/gen/android_cv_wrap.cpp
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V=
/home/florian/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V=
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: *** No rule to make target `../build/android-opencv.mk'. Stop.
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make: *** [libs/armeabi/libandroid-opencv.so] Error 2
make: *** Waiting for unfinished jobs....
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
make[1]: *** No rule to make target `../build/android-opencv.mk'. Stop.
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2
有人知道这意味着什么以及我可以做什么来构建共享库吗?
...
好吧,在查看了错误消息后,我发现构建目录中似乎缺少一些东西...但是 android 文件夹中甚至没有构建目录,所以我创建了一个,运行'在那里输入“cmake”,然后再次“make”,但出现此错误:
Compile thumb : opencv_lapack <= /home/florian/android-opencv-willowgarage/3rdparty/lapack/sgetrf.c
Compile thumb : opencv_lapack <= /home/florian/android-opencv-willowgarage/3rdparty/lapack/scopy.c
Compile++ thumb: opencv_core <= /home/florian/android-opencv-willowgarage/modules/core/src/matrix.cpp
cc1plus: error: /home/florian/android-opencv-willowgarage/android/../modules/index.rst/include: Not a directory
make[3]: *** [/home/florian/android-opencv-willowgarage/android/build/obj/local/armeabi/objs/opencv_core/src/matrix.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [android-opencv] Error 2
make[1]: *** [CMakeFiles/ndk.dir/all] Error 2
make: *** [all] Error 2
有人知道这意味着什么吗?
PLEASE SEE THE ADDITIONS AT THE BOTTOM! The first problem is solved in Linux, not under Windows and Cygwin yet, but there is a new problem. Please see below!
I am currently trying to compile OpenCV for Android NDK so that I can use it in my apps. For this I tried to follow this guide:
http://www.stanford.edu/~zxwang/android_opencv.html
But when compiling the downloaded stuff with ndk-build I get this error:
$ /cygdrive/u/flori/workspace/android-ndk-r5b/ndk-build
Compile++ thumb : opencv <= cvjni.cpp
Compile++ thumb : cxcore <= cxalloc.cpp
Compile++ thumb : cxcore <= cxarithm.cpp
Compile++ thumb : cxcore <= cxarray.cpp
Compile++ thumb : cxcore <= cxcmp.cpp
Compile++ thumb : cxcore <= cxconvert.cpp
Compile++ thumb : cxcore <= cxcopy.cpp
Compile++ thumb : cxcore <= cxdatastructs.cpp
Compile++ thumb : cxcore <= cxdrawing.cpp
Compile++ thumb : cxcore <= cxdxt.cpp
Compile++ thumb : cxcore <= cxerror.cpp
Compile++ thumb : cxcore <= cximage.cpp
Compile++ thumb : cxcore <= cxjacobieigens.cpp
Compile++ thumb : cxcore <= cxlogic.cpp
Compile++ thumb : cxcore <= cxlut.cpp
Compile++ thumb : cxcore <= cxmathfuncs.cpp
Compile++ thumb : cxcore <= cxmatmul.cpp
Compile++ thumb : cxcore <= cxmatrix.cpp
Compile++ thumb : cxcore <= cxmean.cpp
Compile++ thumb : cxcore <= cxmeansdv.cpp
Compile++ thumb : cxcore <= cxminmaxloc.cpp
Compile++ thumb : cxcore <= cxnorm.cpp
Compile++ thumb : cxcore <= cxouttext.cpp
Compile++ thumb : cxcore <= cxpersistence.cpp
Compile++ thumb : cxcore <= cxprecomp.cpp
Compile++ thumb : cxcore <= cxrand.cpp
Compile++ thumb : cxcore <= cxsumpixels.cpp
Compile++ thumb : cxcore <= cxsvd.cpp
Compile++ thumb : cxcore <= cxswitcher.cpp
Compile++ thumb : cxcore <= cxtables.cpp
Compile++ thumb : cxcore <= cxutils.cpp
StaticLibrary : libstdc++.a
StaticLibrary : libcxcore.a
Compile++ thumb : cv <= cvaccum.cpp
Compile++ thumb : cv <= cvadapthresh.cpp
Compile++ thumb : cv <= cvapprox.cpp
Compile++ thumb : cv <= cvcalccontrasthistogram.cpp
Compile++ thumb : cv <= cvcalcimagehomography.cpp
Compile++ thumb : cv <= cvcalibinit.cpp
Compile++ thumb : cv <= cvcalibration.cpp
Compile++ thumb : cv <= cvcamshift.cpp
Compile++ thumb : cv <= cvcanny.cpp
Compile++ thumb : cv <= cvcolor.cpp
Compile++ thumb : cv <= cvcondens.cpp
Compile++ thumb : cv <= cvcontours.cpp
Compile++ thumb : cv <= cvcontourtree.cpp
Compile++ thumb : cv <= cvconvhull.cpp
Compile++ thumb : cv <= cvcorner.cpp
Compile++ thumb : cv <= cvcornersubpix.cpp
Compile++ thumb : cv <= cvderiv.cpp
Compile++ thumb : cv <= cvdistransform.cpp
Compile++ thumb : cv <= cvdominants.cpp
Compile++ thumb : cv <= cvemd.cpp
Compile++ thumb : cv <= cvfeatureselect.cpp
Compile++ thumb : cv <= cvfilter.cpp
Compile++ thumb : cv <= cvfloodfill.cpp
Compile++ thumb : cv <= cvfundam.cpp
Compile++ thumb : cv <= cvgeometry.cpp
Compile++ thumb : cv <= cvhaar.cpp
Compile++ thumb : cv <= cvhistogram.cpp
Compile++ thumb : cv <= cvhough.cpp
Compile++ thumb : cv <= cvimgwarp.cpp
Compile++ thumb : cv <= cvinpaint.cpp
Compile++ thumb : cv <= cvkalman.cpp
Compile++ thumb : cv <= cvlinefit.cpp
Compile++ thumb : cv <= cvlkpyramid.cpp
Compile++ thumb : cv <= cvmatchcontours.cpp
Compile++ thumb : cv <= cvmoments.cpp
Compile++ thumb : cv <= cvmorph.cpp
Compile++ thumb : cv <= cvmotempl.cpp
Compile++ thumb : cv <= cvoptflowbm.cpp
Compile++ thumb : cv <= cvoptflowhs.cpp
Compile++ thumb : cv <= cvoptflowlk.cpp
Compile++ thumb : cv <= cvpgh.cpp
Compile++ thumb : cv <= cvposit.cpp
Compile++ thumb : cv <= cvprecomp.cpp
Compile++ thumb : cv <= cvpyramids.cpp
Compile++ thumb : cv <= cvpyrsegmentation.cpp
Compile++ thumb : cv <= cvrotcalipers.cpp
Compile++ thumb : cv <= cvsamplers.cpp
Compile++ thumb : cv <= cvsegmentation.cpp
Compile++ thumb : cv <= cvshapedescr.cpp
Compile++ thumb : cv <= cvsmooth.cpp
Compile++ thumb : cv <= cvsnakes.cpp
Compile++ thumb : cv <= cvstereobm.cpp
Compile++ thumb : cv <= cvstereogc.cpp
Compile++ thumb : cv <= cvsubdivision2d.cpp
Compile++ thumb : cv <= cvsumpixels.cpp
Compile++ thumb : cv <= cvsurf.cpp
Compile++ thumb : cv <= cvswitcher.cpp
Compile++ thumb : cv <= cvtables.cpp
Compile++ thumb : cv <= cvtemplmatch.cpp
Compile++ thumb : cv <= cvthresh.cpp
Compile++ thumb : cv <= cvundistort.cpp
Compile++ thumb : cv <= cvutils.cpp
StaticLibrary : libcv.a
SharedLibrary : libopencv.so
U:/flori/workspace/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebui
lt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-andr
oideabi/bin/ld.exe: cannot find -lcxcore
collect2: ld returned 1 exit status
make: *** [/cygdrive/u/flori/workspace/android/testOpenCV/obj/local/armeabi/libo
pencv.so] Error 1
I am trying to compile it on a Windows system and with the newest NDK version...
Does anybody have an idea what this linking error means and what I can to to have it work again?
Would be great if anybody could help
After getting the problem to work I found that there is another way of compiling OpenCV for Android, using the current version of OpenCV (instead of the 1.1 one from above) and the modified Android NDK from crystax, which supports STL and exceptions and therefore supports the newest OpenCV Version.
All information on that can be found here:
http://opencv.willowgarage.com/wiki/Android
There it says to download the current svn trunk and the crystax-r4 android-ndk, as well as swig, which I did.
I entered the folder, created the build directory, ran cmake and then built the static libs, which seemed to work. At least it successfully ran the make-command without errors.
I now wanted to build the shared libraries so I entered the android-jni folder and ran 'make' again, but got this error:
% make -j4
OPENCV_CONFIG = ../build/android-opencv.mk
make clean-swig &&\
mkdir -p jni/gen &&\
mkdir -p src/com/opencv/jni &&\
swig -java -c++ -package "com.opencv.jni" \
-outdir src/com/opencv/jni \
-o jni/gen/android_cv_wrap.cpp jni/android-cv.i
OPENCV_CONFIG = ../build/android-opencv.mk
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
rm -f jni/gen/android_cv_wrap.cpp
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V=
/home/florian/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V=
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: *** No rule to make target `../build/android-opencv.mk'. Stop.
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make: *** [libs/armeabi/libandroid-opencv.so] Error 2
make: *** Waiting for unfinished jobs....
make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
make[1]: *** No rule to make target `../build/android-opencv.mk'. Stop.
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2
Does anybody have an idea what this means and what I can do to build the shared libraries?
...
Ok after having a look at the error message it came to me that it seems to have something missing in the build directory... but there wasn't even a build directory in the android folder so I created one, ran 'cmake' in there and 'make' again but get this error:
Compile thumb : opencv_lapack <= /home/florian/android-opencv-willowgarage/3rdparty/lapack/sgetrf.c
Compile thumb : opencv_lapack <= /home/florian/android-opencv-willowgarage/3rdparty/lapack/scopy.c
Compile++ thumb: opencv_core <= /home/florian/android-opencv-willowgarage/modules/core/src/matrix.cpp
cc1plus: error: /home/florian/android-opencv-willowgarage/android/../modules/index.rst/include: Not a directory
make[3]: *** [/home/florian/android-opencv-willowgarage/android/build/obj/local/armeabi/objs/opencv_core/src/matrix.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [android-opencv] Error 2
make[1]: *** [CMakeFiles/ndk.dir/all] Error 2
make: *** [all] Error 2
Anybody know what this means?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在 Linux 上用 ndk-r5b 构建了它。您的项目目录中是否有一个
default.properties
文件(不是jni
),其内容如下:如果没有,您可以尝试创建它并再次构建。
I just built it with ndk-r5b on Linux. Do you have a
default.properties
file in your project directory (notjni
) that has something like the following:If not, you might try creating it and building again.
对于 cygwin,标准 gcc 规范文件包括 -dll-search-prefix=cyg,因此实际上我们搜索 cygxxx.dll。 (不适用于 libcxcore.a)因此您需要将 libxxx.a 复制到 cygxxx.a 并将它们放在一些可供链接器目录中。
我可以在 http:// 找到此解决方案docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html
In the case of cygwin, the standard gcc spec file includes -dll-search-prefix=cyg, so in effect we actually search for cygxxx.dll. (not for libcxcore.a) So you need to copy your libxxx.a to cygxxx.a and put them in some available for linker directory.
This solution i'm found at http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html