How to build a shared library and link it in another shared library

296 views
Skip to first unread message

Kartik Aiyer

unread,
May 24, 2018, 11:21:28 AM5/24/18
to android-platform

Hello,

I’m trying to add some vendor code to an AOSP root. I’m basically porting a
library (selected components) that we have written over to Android. The library
component has a dependency on libfmt which I
also have the source for and am building as a shared library.

Here is the tree structure of the vendor folder

└── Core
|   ├── Android.mk
|   ├── cmake_android_all.sh
|   ├── CMakeLists.txt
|   ├── Core
|   │   ├── Android.mk
|   │   ├── Base
|   │   │   ├── Algorithm.cpp
|   │   │   ├── Algorithm.h
|   │   │   ├── Android.mk
|   │   │   ├── ...
|   │   ├── Base.h
|   │   ├── Log
│   │   ├── Android
│   │   │   └── Log.c
│   │   ├── Android.mk
│   │   ├── Apple
│   │   │   └── Log.c
│   │   ├── CMakeLists.txt
│   │   ├── Log.cpp
│   │   └── Log.h
    └── Vendor
    └── fmt
            ├── Android.mk
            ├── ChangeLog.rst
            ├── CMakeLists.txt
            ├── CONTRIBUTING.rst
            └── ...

So The Core project is made of two Sub dirs, Core & Vendor. I have created Android.mk
files for two of the sub projects in Core and for the Vendor dependency in fmt.

fmt has a lot of sources, but for Android only one source file is used src/format.cc
and the Android.mk file was supplied (though I had to correct it) by the project.

libfmt is used Core/Log. I built the components BUILD_SHARED_LIBRARY and even added them
to the PRODUCT_PACKAGES in the device BoardConfig.mk however, whenever it links I get the following error

ninja: error: 'out/target/product/qcs605/obj/SHARED_LIBRARIES/libcom.rylo.fmt_intermediates/export_includes', needed by 'out/target/product/qcs605/obj/SHARED_LIBRARIES/com.rylo.coreLog_intermediates/import_includes', missing and no known rule to make it
15:56:18 ninja failed with: exit status 1

I’m not sure what exactly is causing this problem and as far as I can tell I have done things correctly to build the shared library and reference it in another module.

Here are the relevant Android.mk files

Core/Android.mk

CORE_ROOT_PATH := $(call my-dir)
CORE_SRC_PATH := $(call my-dir)/Core
CORE_VENDOR_PATH := $(call my-dir)/Vendor
include $(CORE_VENDOR_PATH)/fmt/Android.mk
include $(CORE_SRC_PATH)/Android.mk

Core/Core/Android.mk

include $(call all-subdir-makefiles)

Core/Core/Log/Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := ..\
              . \
              ../../Vendor/fmt/include

LOCAL_SRC_FILES := $(call all-cpp-files-under, . )
LOCAL_SRC_FILES += $(catt all-c-files-under, Android )

LOCAL_SHARED_LIBRARIES := libcom.rylo.fmt

LOCAL_MODULE := com.rylo.coreLog

include $(BUILD_SHARED_LIBRARY)

Core/Vendor/fmt/Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_CPPFLAGS += -std=c++11 -fexceptions

LOCAL_MODULE := com.rylo.fmt

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := src/format.cc

include $(BUILD_SHARED_LIBRARY)

Any advice on how to link this up correctly would be much appreciated.

Thanks
Kartik

Colin Cross

unread,
May 24, 2018, 11:34:24 AM5/24/18
to android-...@googlegroups.com
Change LOCAL_MODULE := com.rylo.fmt to libcom.rylo.fmt

--
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.

Kartik Aiyer

unread,
May 25, 2018, 10:48:32 AM5/25/18
to android-...@googlegroups.com
Oh Wow... that was stupid of me... thanks a lot... that worked.


Reply all
Reply to author
Forward
0 new messages