several static libraries into a shared one

2,068 views
Skip to first unread message

deem

unread,
Feb 1, 2011, 2:31:18 PM2/1/11
to android-ndk
Guys,

Could you please help me what I'm doing wrong here?

I have a few static libraries I need to combine into shared one with
my own code in it:

# Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := mymodule
LOCAL_SRC_FILES := mymodulecpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%)

LOCAL_LDLIBS := -L$(LOCAL_PATH)lib -Wl,-whole-archive -llib1 -llib2 -
llib3 -Wl,-no-whole-archive -lssl -lstdc++

LOCAL_STATIC_LIBRARIES := lib1 lib2 lib3

include $(BUILD_SHARED_LIBRARY)

I get a bunch of std namespace errors in exceptions and algorithms

What am I doing wrong, please?

And what is that libstd++.a library gets created and why doe sit have
only 8 bytes length?

Thanks a bunch in advance.

alan

unread,
Feb 2, 2011, 4:31:11 AM2/2/11
to andro...@googlegroups.com
if you are using the r5 ndk then you should be using prebuilts rather than LOCAL_LDLIBS

deem

unread,
Feb 2, 2011, 8:22:24 AM2/2/11
to android-ndk
Copied from removed duplicate topic
I apologize for membership's time wasted reading the duplicates

On 1/31/2011 11:53 PM, deem wrote:

> Guys,

> Could you please help me what I'm doing wrong here?

> I have a few static libraries I need to combine into one shared with
> my own code:

To do this, you should use pre-built static libraries, instead of
trying
to concoct a set of LDLIBS flags.

See docs/PREBUILTS.html for examples.

In short, you create one LOCAL_MODULE for each static library,
pointing
at the .a file as the source. Then your final LOCAL_MODULE lists each
of those previous items in its LOCAL_STATIC_LIBRARIES list.

Also, specifically for the C++ support, you should check out:

docs/CPLUSPLUS-SUPPORT.html

in particular, selecting the correct stl implementation with the
APP_STL
flag.

--Mike

deem

unread,
Feb 2, 2011, 8:33:38 AM2/2/11
to android-ndk
I switched to prebuilds,

but when I use LOCAL_STATIC_LIBRARIES then I get a bunch if unresolved
symbols from the prebuilt static libraries as they use each other
(yes, I know order is important and I follow the required order).

When I use LOCAL_WHOLE_STATIC_LIBRARIES my main module does not see
symbols from the prebuilt libraries.

To resolve it they suggest switching to LOCAL_LDLIBS.

:-)

alan

unread,
Feb 2, 2011, 9:12:30 AM2/2/11
to andro...@googlegroups.com
which symbols are missing? are your static libraries built by the ndk or by calling the compiler directly

deem

unread,
Feb 2, 2011, 9:36:55 AM2/2/11
to android-ndk
the static libraries are (pre)built with NDR r5

Below is a simplified version of Android.mk I use and the undefined
reference errors are coming from main.o when in main.cpp I make a call
to anything from mod1 or mod2.

Let's say I call mod1::getVersion() in main.cpp, then I see "undefined
reference to mod1::getVersion()".

# Android.mk
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := mod1
LOCAL_SRC_FILES := libmod1.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := mod2
LOCAL_SRC_FILES := libmod3.a
include $(PREBUILT_STATIC_LIBRARY)

<...more prebuilt static libs..>

include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_SRC_FILES := main.cpp
LOCAL_WHOLE_STATIC_LIBRARIES := mod1 mod2 <...>
#LOCAL_LDLIBS := -Wl,--whole-archive mod1 mod2 <..>
include $(BUILD_SHARED_LIBRARY)

alan

unread,
Feb 3, 2011, 4:29:35 AM2/3/11
to andro...@googlegroups.com
i'm not sure that LOCAL_WHOLE_STATIC_LIBRARIES is a supported option

David Turner

unread,
Feb 3, 2011, 8:50:19 AM2/3/11
to andro...@googlegroups.com
On Thu, Feb 3, 2011 at 10:29 AM, alan <al...@birtles.org.uk> wrote:
i'm not sure that LOCAL_WHOLE_STATIC_LIBRARIES is a supported option

It should be in NDK r5 (see the changelog). Might be a bug, but I'd like a way to replicate the problem. 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

alan

unread,
Feb 3, 2011, 11:08:25 AM2/3/11
to andro...@googlegroups.com
its not mentioned clearly in the docs (ANDROID-MK.html) which was why i was unsure

eyal zmora

unread,
Feb 3, 2011, 2:33:49 PM2/3/11
to andro...@googlegroups.com
Just to get things right:
If the static library was compiled using gcc and not ndk-build, will the build of the .so fail for sure? or is successfull build not guaranteed? What does it depend on?

2011/2/3 alan <al...@birtles.org.uk>
its not mentioned clearly in the docs (ANDROID-MK.html) which was why i was unsure

alan

unread,
Feb 4, 2011, 4:26:58 AM2/4/11
to andro...@googlegroups.com
if you use ndk-build for everything it should always work.
if you use the standalone gcc shipped with the ndk correctly it should work.
if you use another version of gcc it will almost certainly fail

eyal zmora

unread,
Feb 5, 2011, 2:59:20 PM2/5/11
to andro...@googlegroups.com
Thanks

2011/2/4 alan <al...@birtles.org.uk>
if you use ndk-build for everything it should always work.
if you use the standalone gcc shipped with the ndk correctly it should work.
if you use another version of gcc it will almost certainly fail

deem

unread,
Feb 9, 2011, 10:09:12 PM2/9/11
to android-ndk
it does not work because of a bug in setup.mk from the toolchain you
use

locate the setup.mk file you use, it's one of those:

> find -name setup.mk
./sources/cxx-stl/system/setup.mk
./toolchains/arm-eabi-4.4.0/setup.mk
./toolchains/x86-4.2.1/setup.mk
./toolchains/arm-linux-androideabi-4.4.3/setup.mk

in my case it was "./toolchains/arm-linux-androideabi-4.4.3/setup.mk"

In that setup.mk locate defines cmd-build-shared-library and cmd-build-
executable

In these defines look at the call with $
(PRIVATE_WHOLE_STATIC_LIBRARIES) as a parameter:

$(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES))

make sure that "link-whole-archives" matches the one in build/core/
definitions/mk

In my toolchain I had "whole-link-archives-tags" instead of "link-
whole-archives"

Took me about three hours to figure it out, damn it
Reply all
Reply to author
Forward
0 new messages