Static Prebuilt libraries and their dependencies

72 views
Skip to first unread message

Kartik Aiyer

unread,
Jun 19, 2018, 4:03:25 PM6/19/18
to android-platform
  • I have prebuilt binaries of opencv as static libraries built using the android NDK r16 for arm64-v8a & armeabi-v7a.
  • I’m trying to use these binaries as is in an AOSP build for the same above two architectures.
  • The output of the opencv prebuild seems to have separated the opencv specific .a files from the 3rdparty .a files. I gather this means to link successfully I will have to include both the opencv library (eg libopencvcore.a) as well as the third-party dependency (libtbb.a). _I’m not sure how to specify the 3rdparty dependency in the static prebuild module description.

This is folder structure of the opencv output

sdk
  └── native
    ├── 3rdparty
    │   └── libs
    │       ├── arm64-v8a
    │       │   ├── libcpufeatures.a
    │       │   └── libtbb.a
    │       ├── armeabi-v7a
    │       │   ├── libcpufeatures.a
    │       │   └── libtbb.a
    │       ├── x86
    │       │   ├── libcpufeatures.a
    │       │   ├── libittnotify.a
    │       │   └── libtbb.a
    │       └── x86_64
    │           ├── libcpufeatures.a
    │           ├── libittnotify.a
    │           └── libtbb.a
    ├── jni
    │   ├── android.toolchain.cmake
    │   ├── include
    │   │   ├── opencv
    │   │   │   ├── cvaux.h
    |   |   |   ...
    │   │   └── opencv2
    │   │       ├── core
    └── libs
        ├── arm64-v8a
        │   ├── libopencv_core.a
        │   ├── libopencv_features2d.a
        │   ├── libopencv_imgproc.a
        │   └── libopencv_video.a
        ├── armeabi-v7a
        │   ├── libopencv_core.a
        │   ├── libopencv_features2d.a
        │   ├── libopencv_imgproc.a
        │   └── libopencv_video.a
        ├── x86
        │   ├── libopencv_core.a
        │   ├── libopencv_features2d.a
        │   ├── libopencv_imgproc.a
        │   └── libopencv_video.a
        └── x86_64
            ├── libopencv_core.a
            ├── libopencv_features2d.a
            ├── libopencv_imgproc.a
            └── libopencv_video.a

The dependencies are in the 3rdparty folder.
I created an Android.mk file that makes PREBUILDs out of all the opencv libraries, but I’m not sure how to add the dependencies to the prebuilt module.

This is my current Android.mk file

ROOT_DIR := $(call my-dir)

LOCAL_PATH := $(ROOT_DIR)/core-libs/opencv/Android/sdk/native/libs
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_core_prebuilt
LOCAL_MULTILIB := both
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
LOCAL_SRC_FILES_64 := arm64-v8a/libopencv_core.a
LOCAL_SRC_FILES_32 := armeabi-v7a/libopencv_core.a
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../jni/include
LOCAL_EXPORT_CFLAGS_64 := -L$(LOCAL_PATH)/../3rdparty/libs/arm64-v8a -llibtbb.a -llibcpufeatures.a
LOCAL_EXPORT_CFLAGS_32 := -L$(LOCAL_PATH)/../3rdparty/libs/armeabi-v7a -llibtbb.a -llibcpufeatures.a
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := opencv_features2d_prebuilt
LOCAL_MULTILIB := both
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
LOCAL_SRC_FILES_64 := arm64-v8a/libopencv_features2d.a
LOCAL_SRC_FILES_32 := armeabi-v7a/libopencv_features2d.a
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../jni/include 
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := opencv_imgproc_prebuilt
LOCAL_MULTILIB := both 
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
LOCAL_SRC_FILES_64 := arm64-v8a/libopencv_imgproc.a
LOCAL_SRC_FILES_32 := armeabi-v7a/libopencv_imgproc.a
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../jni/include 
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := opencv_video_prebuilt
LOCAL_MULTILIB := both
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
LOCAL_SRC_FILES_64 := arm64-v8a/libopencv_video.a
LOCAL_SRC_FILES_32 := armeabi-v7a/libopencv_video.a
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../jni/include 
include $(BUILD_PREBUILT)

When I try to link to the opencv prebuilds sure enough I get undefined references for calls into libtbb.

How do I specify the libtbb dependency and how to do I make sure the corresponding 3rdparty .a file is linked together.

Can I add it to the LOCAL_SRC_FILES variable ?

Thanks
Kartik

Colin Cross

unread,
Jun 19, 2018, 4:35:53 PM6/19/18
to android-...@googlegroups.com
The platform build does not support transitive static dependencies.  You'll need to add another prebuilt module for libbb.a, and then either add it as a dependency everywhere you use the opencv prebuilts, or combine them into a single static library:

include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_core_plus_tbb
LOCAL_WHOLE_STATIC_LIBRARIES := opencv_core_prebuilt libtbb_prebuilt
include $(BUILD_STATIC_LIBRARY)

Also, it would be more accurate to use LOCAL_SRC_FILES_arm64 and LOCAL_SRC_FILES_arm instead of LOCAL_SRC_FILES_64 and LOCAL_SRC_FILES_32.



--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To post to this group, send email to android-...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

Tran Hung

unread,
Jul 27, 2018, 11:33:50 AM7/27/18
to android-platform
I guess you're talking about:  Add build dependencies 

Best regards,
Hung Tran


Reply all
Reply to author
Forward
0 new messages