android-opencv cvCanny link error
I'm using android-opencv (android-opencv -- http://code.google.com/p/android-opencv/ -- ) , it was built successfully and worked like charm. Then I tried to use "cvCanny" to detect faces but the linker reported an error "undefined reference".
I tried lot's of things to fix this, but couldn't solve it.
/home1/apps/c/opencv-android/opencv/obj/local/armeabi-v7a/libobjdetect.a(haar.o): In function
cvHaarDetectObjects': /home1/apps/c/opencv-android/opencv/modules/objdetect/src/haar.cpp:1127: undefined reference to
cvCanny' collect2: ld returned 1 exit status
compile command
/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,--whole-archive -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/apps/c/opencv-android/opencv/bin/ndk/local/armeabi-v7a -L/home1/apps/c/opencv-android/opencv/obj/local/armeabi-v7a -Wl,-rpath-link=/home1/apps/c/opencv-android/opencv/obj/local/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/build/platforms/android-5/arch-arm/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
When I inspect "libimgproc.a" with "nm" command, it says it has the symbol of "cvCanny" , but the linker complains ...
nm /home1/apps/c/opencv-android/opencv/obj/local/armeabi-v7a/libimgproc.a | grep cvCanny
00000000 r ZZ7cvCannyE19_PRETTY_FUNCTION__
00000001 T cvCanny
Please give me a hint about this liking problem...?
When using gcc (or g++) to link static libraries with dependencies, order matters.
Since objdetect depends upon imgproc, it must be first:
libopencv_core.a libopencv_highgui.a libopencv_objdetect.a libopencv_imgproc.a
This is because the GNU linker resolves dependencies in the order the arguments are given, discarding any symbols that are unreferenced to that point before moving on.
One way to find if reordering libraries will solve your problem is to repeat all libraries, so that every library list given to the linker after all the others (again). If this solves your link error, then you've got a static library ordering issue.
A solution was found on the android-opencv project site which involved changing the order in which the opencv libraries are loaded.
http://code.google.com/p/android-opencv/issues/detail?id=17
精彩评论