OpenCV2.4 with Android Native Activity

5.5k Views Asked by At

I am currently facing the same problem than presented in this question, except that I use the 2.4 version in stead of the 2.3.1.

I've converted native-activity (from ndk samples) to c++ and modified android.mk and application.mk.

I had the same errors (with ~Mat and so one).

When I read the answers to the question, I realised I needed to add OPENCV_INSTALL_MODULES:=on and OPENCV_LIB_TYPE:=STATIC (which is strange since I have an other project with native openCV which does not require theese two lines).

But it's still not working.

Android.mk is the following :

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on

include includeOpenCV.mk

ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
    #try to load OpenCV.mk from default install location
    include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
else
    include $(OPENCV_MK_PATH)
endif

LOCAL_MODULE    := native-activity
LOCAL_SRC_FILES := main.cpp engine.cpp
LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES += android_native_app_glue


include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

I'm getting the following errors :

./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvPuts(CvFileStorage*, char const*)':
persistence.cpp:(.text._ZL7icvPutsP13CvFileStoragePKc+0x20): undefined reference to `gzputs'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvGets(CvFileStorage*, char*, int)':
persistence.cpp:(.text._ZL7icvGetsP13CvFileStoragePci+0x26): undefined reference to `gzgets'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvXMLSkipSpaces(CvFileStorage*, char*, int)':
persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x1e2): undefined reference to `gzgets'
persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x208): undefined reference to `gzeof'
persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x33c): undefined reference to `gzeof'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `_ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3':
persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x124): undefined reference to `gzgets'
persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x170): undefined reference to `gzeof'
/cygdrive/d/soft/NVPACK/android-ndk-r7c/build/core/build-binary.mk:366: recipe for target `obj/local/armeabi-v7a/libnative-activity.so' failed
persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x28e): undefined reference to `gzeof'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `cvReleaseFileStorage':
persistence.cpp:(.text.cvReleaseFileStorage+0x24): undefined reference to `gzclose'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `cvOpenFileStorage':
persistence.cpp:(.text.cvOpenFileStorage+0x66e): undefined reference to `gzopen'
persistence.cpp:(.text.cvOpenFileStorage+0x8fc): undefined reference to `gzclose'
persistence.cpp:(.text.cvOpenFileStorage+0xaea): undefined reference to `gzrewind'
persistence.cpp:(.text.cvOpenFileStorage+0xbee): undefined reference to `gzrewind'
persistence.cpp:(.text.cvOpenFileStorage+0xc0a): undefined reference to `gzclose'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libnative-activity.so] Error 1

Is there anything I missed ?

3

There are 3 best solutions below

0
On

I ended trying with the native plasma project (in which the display is done by writing in a bitmap) and it worked well.

Maybe GLES was messing with OpenCV. I don't think there is any other difference between the two projects.

In a way the problem is solved. Still, if anyone encounters the same issue and solved it, I would be interested to understand what caused it and how to fix it.

0
On

Although this is an old question, I run into the same issue and fixed it by adding

LOCAL_LDLIBS    += -lz # Compression library

To my Android.mk

2
On

Try to replace

LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv1_CM

with

LOCAL_LDLIBS    += -llog -landroid -lEGL -lGLESv1_CM