Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:56:02+00:00 2026-06-15T07:56:02+00:00

Let’s say we’re building a shared library A that needs to link to 2

  • 0

Let’s say we’re building a shared library A that needs to link to 2 external static libs B and C. All you’ve got are libB.a and libC.a, along with their header files.

Here’s a simplified Android.mk for libA:

LOCAL_LDLIBS := ../external/libB.a ../external/libC.a

include $(BUILD_SHARED_LIBRARY)

AFAIK, the way linking works for shared libraries is:

  1. grab all object files of B and C
  2. strip out object files that A doesn’t reference
  3. resolve references in B and C

This gives link errors because B and C call each other, specifically they call functions that got stripped out in step 2 because A didn’t call them.

If we built the static libs ourselves, then it’s simply a matter of replacing LOCAL_STATIC_LIBRARIES with LOCAL_WHOLE_STATIC_LIBRARIES, which prevents code stripping (at the expense of code size). Under the hood, it passes –whole-archive to the linker.

Since we didn’t build B and C (and don’t even have the source to rebuild them), what are the options?

  1. manually reference the missing functions from A, so that they don’t get stripped
  2. figure out how to pass –whole-archive to the linker for the external static libraries
  3. use the PREBUILT_STATIC_LIBRARY (seen it mentioned, but never used it, and the according to the docs it doesn’t sound applicable in this case)
  4. build an executable instead of a shared library (which won’t strip code the same way)
  5. move/rename external libs to trick the NDK build system into thinking they’re mine, so that I can add them to LOCAL_WHOLE_STATIC_LIBRARIES.

I’ve gone with option 1 because it’s the first thing that worked, but obviously it’s not great. I’m asking whether there’s a better solution.

The answer to this question ( Linking issue when prebuilt static and shared libraries with the Android NDK ) made me wonder if I need to re-evaluate my build setup (shared library linking to external static library). I’m unable to comment there, so I asked my own question here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:56:03+00:00Added an answer on June 15, 2026 at 7:56 am

    The answer can be found in How to deal with recursive dependencies between static libraries using the binutils linker?.

    LOCAL_LDLIBS := -L ../external/ -lB -lC -lB
    

    I took the two-libs NDK sample, and made minimal change to demonstrate the technique on GitHub.

    Update (2017): since 2012, the rules of NDK became more strict, and now it will complain that LOCAL_LDLIBS contains non-system libraries:

    Android NDK: WARNING:Android.module: non-system libraries in linker flags: -la -lb
    Android 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
    Android NDK: current module

    This is just a warning, so you can ignore it.

    Or add space after -l to outsmart the NDK protection:

    LOCAL_LDLIBS := -L ../external/ -l B -l C -l B
    

    Alternatively, you can use

    LOCAL_LDLIBS += -L ../external -Wl,--start-group -l B -l C -Wl,--end-group
    

    If the libraries that are involved are not prebuilt, you don’t need to guess their location (which may be especially tricky when using Android Studio NDK integration). Use

    LOCAL_LDLIBS := -L $(TARGET_OUT) …
    

    There exists an alternative approach, which does not use ‘recursive’ linking. But it involves iterations. First, try to build your shared library the usual way. When this fails with unresolved symbols, copy all these symbols to clipboard, and paste them your Android.mk. Let’s say these symbols are extBa, extBb, and extBc (in the above scenario, I believe that some object of libC does not find these symbols that are defined somewhere in libB, that’s why the link fails). What you need now, add

    LOCAL_LDFLAGS += -Wl,-u'extBa' -Wl,-u'extBb' -Wl,-u'extBc'
    

    You can make the next step, and have this all bundled with libC:

    LOCAL_EXPORT_LDFLAGS += -Wl,-u'extBa' -Wl,-u'extBb' -Wl,-u'extBc'
    

    Now any shared lib that uses libC will not miss these symbols.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I got a Map<String, String> and I wanna remove all the entries
Let's say that I've got a sheet - number one - with over 5000
Let's say that I have a binary that I am building, and I include
Let's say I've got a collection of 10 million documents that look something like
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say I'm building a data access layer for an application. Typically I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.