0

I need to create a library with ar from several object files that are built from sources included in LOCAL_SRC_FILES and then link against it when building the final library.

Is this possible, and if yes - how can I do it?

I looked int substituting BUILD_SHARED_LIBRARY with its expanded variant, but the rabbit hole goes way too deep (i.e. I'm not yet that desperate).

The reason I want to do this is because I've hacked together several small libraries into one and trying to build it as a whole. I know separating them in different modules built as stat with their own Android.mk files is a much better solution, but I'm quite short on time.

EDIT: The premise of the question is no longer valid as I had forgotten to add the source files of some of the libraries to the Android.mk file, and had only added the files of the main library. At the same time I had added the dependencies' headers to LOCAL_C_INCLUDES, and this way they had become link-time dependencies rather than compile-time as I intended them to be. Thus I don't actually need to build a library between compilation and linkage.

The rephrased question:

Is it possible, and if yes, how, to add a custom build step to an Android.mk file that is executed after compilation of source files but before linking them together into the final library/executable?

mcmlxxxvi
  • 1,358
  • 1
  • 11
  • 21

1 Answers1

0

You can always add pre-compiled objects or libraries to your link command, e.g.

LOCAL_LDLIBS += ../external/obj1.o /full/path/obj2.o /other/path/libOther.a
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thanks for the tip, but it was a mistake on my part. Please see the updated question. – mcmlxxxvi Dec 09 '12 at 23:14
  • 1
    So what is the question exactly? Create a static library not by writing `include $(BUILD_STATIC_LIBRARY)`? why? Maybe the piece you are missing is that you don't need a separatd **Android.mk** file for each library target. – Alex Cohn Dec 10 '12 at 07:03
  • The question is whether and how I can perform a custom step between compiling and linking. I don't have any real need for it now that I found my mistake, it's just out of curiosity. Sorry about my previous sloppy rephrasing. – mcmlxxxvi Dec 10 '12 at 11:46
  • Could you please elaborate on not needing a separate makefile? – mcmlxxxvi Dec 10 '12 at 11:47
  • If you look at **two-libs** NDK sample, you will find single **Android.mk** file used to build a static library from `first.c` and a shared library from `second.c` and `libtwolib-first.a`. Same way you can build as many static libraries as you wish, and as many shared libraries as you need -- all in one **Android.mk**. – Alex Cohn Dec 10 '12 at 13:08