i'm trying to build a sample program that uses the opencv4android libraries and am having trouble linking. i've tried various .mk gymnastics to no avail. now i'm at the stage of trying to simply execute g++ from the command line and the linking is failing in the same way. i'm way confused because the files appear to be in the right place(s) and contain the appropriate symbols, but ld is still barfing.
here's the commandline generated by aosp's build process for the linking step:
$ prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-g++ -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/LINKED/cvtest -Lout/target/product/maguro/obj/lib -Wl,-rpath-link=out/target/product/maguro/obj/lib -lc -lstdc++ -lm out/target/product/maguro/obj/lib/crtbegin_dynamic.o out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/cvtest.o -Wl,--whole-archive -Wl,--no-whole-archive -Wl,-z,noexecstack -Wl,--icf=safe -Wl,--fix-cortex-a8 -Wl,--no-undefined /home/jeremy/src/aosp/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/armv7-a/libgcc.a out/target/product/maguro/obj/lib/crtend_android.o
running this command generates a number of undefined reference errors:
target Executable: cvtest (out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/LINKED/cvtest)
/home/jeremy/src/aosp/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/cvtest.o: in function main:external/pvl/cvtest/cvtest.c:13: error: undefined reference to 'cvCreateImage'
collect2: ld returned 1 exit status
make: *** [out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/LINKED/cvtest] Error 1
make: Leaving directory `/home/jeremy/src/aosp'
you'll notice that the build process did not generate any linker directives related to opencv, which is strange, becuase they are listed in the .mk . here's one example i've tried:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cvtest
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := cvtest.c
LOCAL_CFLAGS += -L$(LOCAL_PATH)
LOCAL_CFLAGS += -lopencv_core
LOCAL_C_INCLUDES := "$(LOCAL_PATH)/include/" "$(LOCAL_PATH)/include/opencv"
include $(BUILD_EXECUTABLE)
note that i've copied the relevant header and library files to the same working directory as the project code. so i decided to re-run the g++ command and add some linker flags of my own:
$ prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-g++ -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/LINKED/cvtest -Lexternal/pvl/cvtest -Lout/target/product/maguro/obj/lib -Wl,-rpath-link=out/target/product/maguro/obj/lib -lc -lstdc++ -lm -lopencv_core out/target/product/maguro/obj/lib/crtbegin_dynamic.o out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/cvtest.o -Wl,--whole-archive -Wl,--no-whole-archive -Wl,-z,noexecstack -Wl,--icf=safe -Wl,--fix-cortex-a8 -Wl,--no-undefined /home/jeremy/src/aosp/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/armv7-a/libgcc.a out/target/product/maguro/obj/lib/crtend_android.o
but this fails in exactly the same way:
$ /home/jeremy/src/aosp/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/cvtest.o: in function main:external/pvl/cvtest/cvtest.c:13: error: undefined reference to 'cvCreateImage'
collect2: ld returned 1 exit status
make: *** [out/target/product/maguro/obj/EXECUTABLES/cvtest_intermediates/LINKED/cvtest] Error 1
make: Leaving directory `/home/jeremy/src/aosp'
it's clear that the directives are being processed, because if i remove the -L, ld complains about not being able to find libopencv_core.a . furthermore, libopencv_core.a does appear to have the necessary symbol:
$ nm libopencv_core.a | grep cvCreateImage
00000001 T cvCreateImage
00000001 T cvCreateImageHeader
U cvCreateImage
so i'm at a loss right now. anyone have experience with similar linker weirdness? or is there more work that i'm not doing to make the link step work?
many thanks,
jeremy