opencvandroid-ndkubuntu-13.04android-make

OpenCV/NDK - zlib compiling issues in android makefile


I have been trying to compile my shared library which includes OpenCV libraries. My sample android make files is as below:

LOCAL_PATH := (call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencvXXX
LOCAL_SRC_FILES := libs/opencv/libopencvXXX.a
include $(PREBUILT_STATIC_LIBRARY)

OPENCV_LIB_TYPE := STATIC
OPENCV_INSTALL_MODULES := on
OPENCV_CAMERA_MODULES := on

LOCAL_MODULE := libXXX
LOCAL_CPPFLAGS := -std=c++11 -fexceptions
LOCAL_CPP_FEATURES += exceptions
LOCAL_CFLAGS := -std=gnu++11 -fexceptions
LOCAL_LDLIBS := -llog -ldl

LOCAL_SRC_FILES := XXX.cpp
LOCAL_C_INCLUDES := <path to opencv header files>

LOCAL_STATIC_LIBRARIES := stdc++
LOCAL_STATIC_LIBRARIES += libopencvXXX

include $(BUILD_SHARED_LIBRARY)

However, it keeps throwing below errors:

[INFO] jni/libs/opencv/libopencv_core.a(persistence.cpp.o):persistence.cpp:function icvGets(CvFileStorage*, char*, int): error: undefined reference to 'gzgets'
[INFO] jni/libs/opencv/libopencv_core.a(persistence.cpp.o):persistence.cpp:function icvXMLSkipSpaces(CvFileStorage*, char*, int): error: undefined reference to 'gzeof'

I tried several options like below.

LOCAL_LDLIBS += -lz
LOCAL_LDLIBS += -L<NDK root>/platforms/android-19/arch-arm/usr/lib -lz

But nothing helped. Does someone has any clue how I can fix this?

EDIT: Forgot to add that when I add these above two options including '-lz', it throws an error saying "No native compiled library found, did the native compile complete successfully!".


Solution

  • I found the issue. I was supposed to add

    include $(CLEAR_VARS)

    after including all static libraries. Below is the corrected Android.mk

    LOCAL_PATH := (call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := libopencvXXX
    LOCAL_SRC_FILES := libs/opencv/libopencvXXX.a
    include $(PREBUILT_STATIC_LIBRARY)
    
    include $(CLEAR_VARS)
    
    OPENCV_LIB_TYPE := STATIC
    OPENCV_INSTALL_MODULES := on
    OPENCV_CAMERA_MODULES := on
    
    LOCAL_MODULE := libXXX
    LOCAL_CPPFLAGS := -std=c++11 -fexceptions
    LOCAL_CPP_FEATURES += exceptions
    LOCAL_CFLAGS := -std=gnu++11 -fexceptions
    LOCAL_LDLIBS := -llog -ldl
    
    LOCAL_SRC_FILES := XXX.cpp
    LOCAL_C_INCLUDES := <path to opencv header files>
    
    LOCAL_STATIC_LIBRARIES := stdc++
    LOCAL_STATIC_LIBRARIES += libopencvXXX
    
    include $(BUILD_SHARED_LIBRARY)