我正在使用android-opencv(android-opencv - http://code.google.com/p/android-opencv/ - ),它已经成功构建并且像魅力一样工作。 然后我尝试使用“cvCanny”来检测面,但链接器报告错误“未定义的引用”。
我尝试了很多东西来解决这个问题,但无法解决它。
/home1/apps/c/opencv-android/opencv/obj/local/armeabi-v7a/libobjdetect.a(haar.o): 在函数
cvHaarDetectObjects': /home1/apps/c/opencv-android/opencv/modules/objdetect/src/haar.cpp:1127: undefined reference to
cvCanny'中 collect2:ld返回1退出状态
编译命令
/home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc -nostdlib -Wl,-soname,libandroid-opencv.so -Wl,-shared,-Bsymbolic / home1 / apps / c / opencv-android / opencv / android / obj / local / armeabi-v7a / objs / android-opencv / yuv420sp2rgb.o /home1/apps/c/opencv-android/opencv/android/obj/local/armeabi-v7a/objs/android-opencv/gen/android_cv_wrap.o /home1/apps/c/opencv-android/opencv/android/obj/local/armeabi-v7a/objs/android-opencv/image_pool.o /home1/apps/c/opencv-android/opencv/android/obj/local/armeabi-v7a/objs/android-opencv/gl_code.o /home1/apps/c/opencv-android/opencv/android/obj/local/armeabi-v7a/objs/android-opencv/Calibration.o / home1 / apps / c / opencv-android / opencv / android / obj / local /armeabi-v7a/objs/android-opencv/Processor.o /home1/apps/c/opencv-android/opencv/android/obj/local/armeabi-v7a/objs/android-opencv/gen/cvcamera_swig.o -Wl, - 整个存档-Wl, - no-whole-archive /home1/android-ndk-crystax/build/platforms/android-5/arch-arm/usr/lib/libmissing.a /home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../ .. /../arm-eabi/lib/libstdc++.a /home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../ .. /../arm-eabi/lib/libsupc++.a /home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/libgcc.a /home1/android-ndk-crystax/build/platforms/android-5/arch-arm/usr/lib/libc.so /home1/android-ndk-crystax/build/platforms/android-5/arch-arm/usr/lib/libm.so -Wl, - fix-cortex-a8 -Wl, - no-undefined -Wl,-z,noexecstack -L / home1 / android-ndk-crystax / build / platforms / android-5 / arch-arm / usr / LIB -L /和home1 /应用/ C / OpenCV的功能的Android / OpenCV的/ bin中/ NDK /本地/ armeabi-V7A -L /和home1 /应用/ C / OpenCV的功能的Android / OpenCV的/ OBJ /本地/ armeabi-V7A -Wl,-rpath链路= /和home1 /应用/ C /的OpenCV-机器人/ OpenCV的/ OBJ /本地/ armeabi-V7A -lfeatures2d -lcalib3d -limgproc -lvideo -lhighgui -lml -llegacy -lcore -lopencv_lapack -lflann -lobjdetect -lzlib -lpng -ljpeg -ljasper -llog -lGLESv2 -Wl,-rpath-link = / home1 / android-ndk-crystax /建造/平台/机器人-5 /拱形臂/ usr / lib中 /home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../ .. /../arm-eabi/lib/libstdc++.a /home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../ .. /../arm-eabi/lib/libsupc++.a /home1/android-ndk-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/libgcc.a -o /home1/apps/c/opencv-android/opencv/android/obj/local/armeabi-v7a/libandroid-opencv.so
当我用“nm”命令检查“libimgproc.a”时,它表示它的符号为“cvCanny”,但链接器抱怨...
纳米 /home1/apps/c/opencv-android/opencv/obj/local/armeabi-v7a/libimgproc.a | grep cvCanny
00000000 r ZZ7cvCannyE19 _PRETTY_FUNCTION__
00000001 T cvCanny
请给我一个关于这个喜欢问题的提示......?
答案 0 :(得分:2)
当使用gcc(或g ++)将静态库与依赖项链接时,命令很重要。
由于objdetect依赖于imgproc,它必须是第一个:
libopencv_core.a libopencv_highgui.a libopencv_objdetect.a libopencv_imgproc.a
这是因为GNU链接器按照给定参数的顺序解析依赖关系,在继续之前丢弃任何未引用该点的符号。
查找重新排序库是否可以解决您的问题的一种方法是重复所有库,以便在所有其他库(再次)之后将每个库列表提供给链接器。如果这解决了链接错误,那么您就会遇到静态库排序问题。
答案 1 :(得分:1)
在android-opencv项目站点上找到了一个解决方案,该解决方案涉及更改opencv库的加载顺序。