Linking shared library with multiple static libraries

2,307 views
Skip to first unread message

eugene

unread,
Dec 24, 2009, 9:24:49 AM12/24/09
to android-ndk
I'm building an application which takes advantage of FFmpeg to decode
audio streams.
My application is using native library which needs three FFmpeg
libraries: libavutil, libavcodec, libavformat.
These libraries depend on each other, specifically libavcodec needs
libavutil, libavformat needs libavutil and libavcodec. No circular
dependencies.
At first I was linking my native lib with these three libraries
dynamically, but since Android 1.5 has an issue which prevents loading
of third party libs depending on other third party libs, I decided to
use static linking.
But this also seems to not work! Static linking only works if you have
single static library. If you need to link shared library with two ore
more static libraries, this just doesn't work - linker complains about
unresolved symbols.
What can I do to achieve my goal?
Is there a patch for NDK 1.6 to make it link multiple static
libraries?
Or workaround for Android 1.5 to make it load libraries with
dependencies?

HeHe

unread,
Dec 24, 2009, 7:09:03 PM12/24/09
to android-ndk

luckily, my share library can link three static libraries, one of
which is speex and another is a sip stack, all in C.

there may be something wrong with your android.mk, i guess.

Eugene Mymrin

unread,
Dec 25, 2009, 10:36:11 AM12/25/09
to andro...@googlegroups.com
Well probably linking with independent static libraries works.
But in my case static libraries use each other, and that's where my
problem seems to lie.
Can anybody from NDK team help me?

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

David Turner

unread,
Dec 25, 2009, 4:11:41 PM12/25/09
to andro...@googlegroups.com
On Unix, the order of static libraries listed in your LOCAL_STATIC_LIBRARIES is important.
Dependent libraries must appear _before_ the other libraries they depend on, otherwise the
static linker will not be able to resolve symbols properly.

In this specific case, you could probably try something like:

  LOCAL_STATIC_LIBRARIES := libavformat libavcodec libavutil

Let me know if this doesn't work. Also, I assume that your "no circular dependencies" statement is correct.
Otherwise, you'll probably need to repeat libraries in this definition to overcome this.

Eugene Mymrin

unread,
Dec 25, 2009, 6:07:51 PM12/25/09
to andro...@googlegroups.com
Thank you, David!
Reordering static libraries using "most dependent library is the
first" rule solved the problem.
I suspected linker wanted the libraries to be properly ordered, but I
listed them in reverse order, putting dependent libraries at the end
of the list.
I should have been thinking more flexibly...

purvi

unread,
Jan 4, 2010, 12:45:26 PM1/4/10
to android-ndk
Hi,

I am facing a problem thou not similar one but I think there is link.
I am having an external shared library libexternall.so. I want to link
this library dynamically in my native code.
So in my Android.mk I add the line LOCAL_LDLIBS = -lexternall (this is
in the ndk docs to load external libraries.).
Now I am not able to figure out where exactly should I place my
libexternall.so so that the compiler takes the path of sharedlibrary
while it compiles my code.
Can anyone please help me out with this?

Thanks.
Regards,
Purvi

On Dec 25 2009, 6:07 pm, Eugene Mymrin <emym...@gmail.com> wrote:
> Thank you, David!
> Reordering static libraries using "most dependent library is the
> first" rule solved the problem.
> I suspected linker wanted the libraries to be properly ordered, but I
> listed them in reverse order, putting dependent libraries at the end
> of the list.
> I should have been thinking more flexibly...
>
>
>
> On Sat, Dec 26, 2009 at 12:11 AM, David Turner <di...@android.com> wrote:
> > On Unix, the order of static libraries listed in your LOCAL_STATIC_LIBRARIES
> > is important.
> > Dependent libraries must appear _before_ the other libraries they depend on,
> > otherwise the
> > static linker will not be able to resolve symbols properly.
> > In this specific case, you could probably try something like:
> >   LOCAL_STATIC_LIBRARIES := libavformat libavcodec libavutil
> > Let me know if this doesn't work. Also, I assume that your "no circular
> > dependencies" statement is correct.
> > Otherwise, you'll probably need to repeat libraries in this definition to
> > overcome this.
>

> >http://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

eugene

unread,
Jan 11, 2010, 11:59:58 PM1/11/10
to android-ndk
I copied my external shared library into
\android-ndk-1.6_r1\build\prebuilt\windows\arm-eabi-4.2.1\arm-eabi\lib
and then my android.mk file could find it using LOCAL_LDLIBS := -
lname


HeHe - can I ask how are you accessing your android device's audio
hardware? Are you using a third-party media module in C as well?

Best regards
Eugene

> > >http://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -

HeHe

unread,
Jan 12, 2010, 1:39:25 AM1/12/10
to android-ndk
no, i use AudioRecord & AudioTrack classes.

> > > >http://groups.google.com/group/android-ndk?hl=en.-Hidequoted text -

David Turner

unread,
Jan 12, 2010, 7:35:21 AM1/12/10
to andro...@googlegroups.com
On Mon, Jan 11, 2010 at 8:59 PM, eugene <eugene...@dolby.com> wrote:
I copied my external shared library into
\android-ndk-1.6_r1\build\prebuilt\windows\arm-eabi-4.2.1\arm-eabi\lib
and then my android.mk file could find it using  LOCAL_LDLIBS := -
lname

you don't need to do that at all, simply use LOCAL_LDLIBS := path/to/your/library.a
and this will just work, without modifying the NDK directories.
 
Reply all
Reply to author
Forward
0 new messages