3

I am trying to built a static library in aosp, which is then used by another program.

Android.bp is for the static library is as follows:

cc_library_static {
    name: "libabc",

    srcs: [
        "src/abc.c",
        "src/abcd.c",
    ],

    include_dirs: [
        "my_folder/inc",
    ],
    vendor: true,
}

Although the build is successful, I am not able to find my libabc.a in my outputs folder.

Do I have to add libabc.a in PRODUCT_PACKAGES for it to be added to the build ? What am I missing here ?

foo
  • 71
  • 2
  • 8
  • 1
    Why would you want to have static libraries on your device? Soong will build `libabc` as soon as a package in `PRODUCT_PACKAGES` depends on it. – Simpl Oct 25 '19 at 10:33
  • @Simpl so how does it link my static lib to my sample program ? While building my sample program, I am getting link error. So I thought I had to include libabc.a path to srcs – foo Oct 25 '19 at 11:23
  • I did add the libabc in static_libs section of Android.bp for sample program – foo Oct 25 '19 at 11:25
  • Adding `libabc` to your modules `static_libs` is correct. Please attach your linker error. – Simpl Oct 25 '19 at 11:27
  • @Simpl It throws "error : undefined reference to functions_in_libabc" – foo Oct 25 '19 at 11:29

1 Answers1

1

It's hard to tell without the seeing sources. My first guess is that your build configuration is fine and the functions_in_libabc is not in any files listed in your srcs list.

You can find libabc.a in out/soong/.intermediates/ and check whether it contains your missing reference.

nm $(find $ANDROID_BUILD_TOP/out/soong/.intermediates -name 'libabc.a')

All you have to do in the module depending on libabc is adding it to the static_libs list.

cc_binary {
    name: "my-module",
    srcs: [ "main.cpp" ],
    static_libs: [ "libabc" ],
}
Simpl
  • 1,938
  • 1
  • 10
  • 21