LOCAL_LDLIBS vs. LOCAL_LDFLAGS

The main differences are the following:

  • LOCAL_LDFLAGS appear before the list of object files and libraries on the final linker command-line, this is where you want to put actual "flags" that affect linker behaviour.

  • LOCAL_LDLIBS appear after the list of object files and libraries on the final linked command-line, this is where you want to put actual system library dependencies.

The distinction exists because of the way static linking works on Unix, i.e. the order of object files, static libraries and shared libraries is very important to determine the final result, and sometimes you really to ensure that something appears before / after the other.

In the end, I recommend following the documentation, i.e.:

  • Put real linker flags into LOCAL_LDFLAGS

  • Put system library dependencies into LOCAL_LDLIBS

  • Only use LOCAL_LDLIBS for system library dependencies. If you want to point to another library, it's much better to list them in either LOCAL_STATIC_LIBRARIES and LOCAL_SHARED_LIBRARIES (even if this means defining a PREBUILT_XXX module for them), because this lets the build system work out dependencies and ordering automatically for you.


It is possible that there is not a functional difference at the present time (or that this is a minor mistake in the documentation) but the intent (in accordance with longstanding tradition of naming variables of this type) is that:

  • LOCAL_LDLIBS would specify libraries or at least objects to be linked into the result

  • LOCAL_LDFLAGS would specify other configuration options to the linker