Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LOCAL_LDLIBS vs. LOCAL_LDFLAGS

The Android NDK guide explains the two variables in the Adnroid.mk as follows:

LOCAL_LDLIBS - The list of additional linker flags to be used when building your shared library or executable.
...


LOCAL_LDFLAGS - The list of other linker flags to be used when building your shared library or executable.
...

So what is the difference between these two?

like image 766
Baruch Avatar asked Mar 12 '14 14:03

Baruch


People also ask

What is Local_ldflags?

LOCAL_LDFLAGS - The list of other linker flags to be used when building your shared library or executable.

What are mk files in Android?

Overview. The Android.mk file resides in a subdirectory of your project's jni/ directory, and describes your sources and shared libraries to the build system. It is really a tiny GNU makefile fragment that the build system parses once or more.


1 Answers

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.

like image 63
Digit Avatar answered Sep 21 '22 17:09

Digit