Circular Dependency of static libraries in Android makefile

712 views
Skip to first unread message

Divij Bhatt

unread,
Mar 3, 2014, 8:00:05 AM3/3/14
to andro...@googlegroups.com
We are working on a project where we need to create a shared library from the static libraries. The issues we are facing is the static libraries contains a circular dependency. Following is the sample of my makefile:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) 
LOCAL_MODULE := Mylib1
LOCAL_SRC_FILES := lib/libMylib1.a
include $(PREBUILT_STATIC_LIBRARY)
           ....
           ....
           ....

LOCAL_MODULE  := DisplayDriver
LOCAL_SRC_FILES := \
            file1.c \
            file2.c \
            file3.c

LOCAL_STATIC_LIBRARIES := -Wl,--start-group \
                       Mylib1 \
                       Mylib2 \
                       Mylib3 \
                       Mylib4 \
                      -Wl,--end-group

LOCAL_C_INCLUDES :=  \
           $(LOCAL_PATH)/include \
           $(LOCAL_PATH)/examples 

LOCAL_CFLAGS := -x c -DHAVE_STDINT -DHAVE_SETENV -DNDEBUG -c
LOCAL_LDLIBS += -llog
APP_ABI := armeabi-v7a
include $(BUILD_SHARED_LIBRARY)
When I give the ndk-build V=1 I can see in the output that clearly -Wl,--start-group and -Wl,--end-group is removed from the compilation when it is going to create the shared library. So is there any other flags which is obvious and I am missing the same?
On the other side if I will give it in LOCAL_LDLIBS like -Wl,--start-group $(LOCAL_STATIC_LIBRARIES)  -Wl,--end-group, I am able to create the shared library but seeing the following warning:
Android NDK: WARNING:jni/Android.mk:BasicClient: non-system libraries in linker flags: jni/lib/libA.a jni/lib/libB.a jni/lib/libB.a jni/lib/libC.aAndroid NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the

. I am using NDK R9, ARM arch.
Thanks in Advance for any inputs!!



David Turner

unread,
Mar 3, 2014, 4:14:11 PM3/3/14
to andro...@googlegroups.com
LOCAL_STATIC_LIBRARIES should only list module names, the -Wl,--start-group and -Wl,--end-group are ignored due to this.

Generally speaking all you need is list your libraries with LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES.

Hope this helps.


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

Message has been deleted

Divij Bhatt

unread,
Mar 4, 2014, 9:07:28 AM3/4/14
to andro...@googlegroups.com
Thanks Digit for your input, I tried using LOCAL_WHOLE_STATIC_LIBRARIES but it gives some undefined reference issue, so using the LOCAL_ALLOW_UNDEFINED_SYMBOLS := true I am able suppress them to create the .so but while loading the same it give the undefined reference error.
It seems they have added this warning in NDK R9 only before with NDK 8 and all -Wl,--start-group and -Wl,--end-group was working as usual.

David Turner

unread,
Mar 4, 2014, 4:53:44 PM3/4/14
to andro...@googlegroups.com
On Tue, Mar 4, 2014 at 12:20 PM, Divij Bhatt <divij...@gmail.com> wrote:
Thanks Digit for your input, I tried using LOCAL_WHOLE_STATIC_LIBRARIES but it gives some undefined reference issue, so using the LOCAL_ALLOW_UNDEFINED_SYMBOLS := true I am able suppress them to create the .so but while loading the same it give the undefined reference error.
It seems they have added this warning in NDK R9 only before with NDK 8 and all -Wl,--start-group and -Wl,--end-group was working as usual.

NDK r9 changed the way module dependencies are computed to fix some nasty bugs, but in all cases, the content of LOCAL_STATIC_LIBRARIES has always been documented as supporting only module names.

Where are these undefined symbols defined exactly? In one of the libraries listed in LOCAL_WHOLE_STATIC_LIBRARIES? If so, this looks like a serious bug. Do you have a simple repro case for this?

Divij Bhatt

unread,
Mar 10, 2014, 3:18:34 AM3/10/14
to andro...@googlegroups.com
The undefined symbols are coming from one of the library in LOCAL_WHOLE_STATIC_LIBRARIES. Yep, it seems like a bug, will need to look in the -fvisibility  options while creating the shared library. As well as also need to see if we can club multiple static libs in to a single lib.
 
 
Reply all
Reply to author
Forward
0 new messages