Android.mk: Multiple libraries accessing OpenCV

417 views
Skip to first unread message

Zohob

unread,
Jul 25, 2012, 4:50:59 AM7/25/12
to android...@googlegroups.com
Hello,

(please excuse that I'm not very familiar with makefiles) My current Makefile looks like this:

LOCAL_PATH := $(call my-dir)

#
#    Library One
#
include $
(CLEAR_VARS)
LOCAL_MODULE    
:= LibOne
LOCAL_SRC_FILES
:= LibOne.cpp
LOCAL_LDLIBS
+=  -llog
include $
(BUILD_STATIC_LIBRARY)

#
#    All libraries using OpenCV united
#
include $
(CLEAR_VARS)
OPENCV_LIB_TYPE
:=STATIC
OPENCV_INSTALL_MODULES
:=on
include
../OpenCV-2.4.1/share/opencv/OpenCV.mk

LOCAL_MODULE    
:= MyLib
LOCAL_SRC_FILES
:= LibTwo.cpp LibThree.cpp
LOCAL_STATIC_LIBRARIES
+= LibOne

LOCAL_LDLIBS
+=  -llog -ldl -ljnigraphics -landroid

include $
(BUILD_SHARED_LIBRARY)

As you see, I have LibOne, which does not need OpenCV and LibTwo plus LibThree, which need OpenCV.
What I want to acchieve is to separate LibTwo and LibThree (as I did it with LibOne). But when I do this

LOCAL_PATH := $(call my-dir)

#
#    Library One
#
include $
(CLEAR_VARS)
LOCAL_MODULE    
:= LibOne
LOCAL_SRC_FILES
:= LibOne.cpp
LOCAL_LDLIBS
+=  -llog
include $
(BUILD_STATIC_LIBRARY)

#
#    OpenCv
#
include $
(CLEAR_VARS)
OPENCV_LIB_TYPE
:=STATIC
OPENCV_INSTALL_MODULES
:=on
include
../OpenCV-2.4.1/share/opencv/OpenCV.mk

#
#    Library Two
#
include $
(CLEAR_VARS)
LOCAL_MODULE    
:= LibTwo
LOCAL_SRC_FILES
:= LibTwo.cpp
include $
(BUILD_STATIC_LIBRARY)

#
#    Library
#
# include $(CLEAR_VARS) <----------- notice/remember this line!
LOCAL_MODULE    
:= MyLib
LOCAL_SRC_FILES
:= LibThree.cpp
LOCAL_STATIC_LIBRARIES
+= LibOne LibTwo

LOCAL_LDLIBS
+=  -llog -ldl -ljnigraphics -landroid

include $
(BUILD_SHARED_LIBRARY)

The compiling aborts with the error
 jni/Android.mk:MyLib: LOCAL_MODULE_FILENAME should not include file extensions
This is of course because I did not use #include $(CLEAR_VARS) before the definition of MyLib. But if I do so, the OpenCV-Stuff is not accessible by MyLib!
So my Question is:

how to define multiple libraries using OpenCV?
Is there a way to add the OpenCV-library into LOCAL_STATIC_LIBRARIES?

Alexander Smorkalov

unread,
Jul 27, 2012, 2:34:11 AM7/27/12
to android...@googlegroups.com
Hello Zohob,

There is no official supported way to use OpenCV library twice in the same Android.mk file. I add ticket about it on issue tracker here: link. I suggest that the problem will be solved in the nearest release of OpenCV for Android.
The only solution I can recommend is using internal OpenCV.mk variables. Here is an example how to build OpenCV tutorial4 with two libs:

LOCAL_PATH := $(call my-dir)

include ../../sdk/native/jni/OpenCV.mk

include $(CLEAR_VARS)

LOCAL_MODULE    := mixed_sample
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES)
LOCAL_CFLAGS     += $(OPENCV_LOCAL_CFLAGS)
LOCAL_LDLIBS += -L../../sdk/native/libs/$(TARGET_ARCH_ABI) $(foreach lib, $(OPENCV_LIBS), -lopencv_$(lib))
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := mixed_sample2
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES)
LOCAL_CFLAGS     += $(OPENCV_LOCAL_CFLAGS)
LOCAL_LDLIBS += -L../../sdk/native/libs/$(TARGET_ARCH_ABI) $(foreach lib, $(OPENCV_LIBS), -lopencv_$(lib))
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

Both libs uses the same dynamic library libopencv_java.so from ndk.
The makefile was tested with OpenCV 2.4.2 and android ndk r8.

Regards, Alexander
Reply all
Reply to author
Forward
0 new messages