When building a fully statically linked binary with the c++-static STL on Android, libandroid_support.a gets linked unconditionally, which leads to multiple definition errors like:
external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: external/androidndk/ndk/platforms/android-29/arch-arm/usr/lib/../lib/libc.a(locale.o): multiple definition of 'duplocale'
As I understand it, libandroid_support.a is only supposed to be used on API versions older than 21 and only on armeabi-v7a and x86.
git clone https://gist.github.com/dcda157428e60489efa7a2f9346e581e.git
cd dcda157428e60489efa7a2f9346e581e
# Both armeabi-v7a and x86 fail
bazel build --config=android_armeabi-v7a :main
bazel build --config=android_x86 :main
What operating system are you running Bazel on?
Ubuntu 20.04.1 on WSL2
What's the output of bazel info release?
3.7.2
If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.
n/a
What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
n/a
Have you found anything relevant by searching the web?
Description of the problem / feature request:
When building a fully statically linked binary with the
c++-static
STL on Android,libandroid_support.a
gets linked unconditionally, which leads to multiple definition errors like:As I understand it,
libandroid_support.a
is only supposed to be used on API versions older than 21 and only on armeabi-v7a and x86.I suspect this behavior is caused by the glob defined here: https://github.com/bazelbuild/bazel/blob/8346ea4cfdd9fbd170d51a528fee26f912dad2d5/src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/NdkPaths.java#L270-L271
libandroid_support.a
is in the same directory aslibc++_static.a
.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I've created a simple repro here: https://gist.github.com/chenxiaolong/dcda157428e60489efa7a2f9346e581e
What operating system are you running Bazel on?
Ubuntu 20.04.1 on WSL2
What's the output of
bazel info release
?3.7.2
If
bazel info release
returns "development version" or "(@non-git)", tell us how you built Bazel.n/a
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?n/a
Have you found anything relevant by searching the web?
This was the same issue, but for CMake: https://github.com/android/ndk/issues/17
This is the comment from an NDK maintainer mentioning that libandroid_support is mean for API <21: https://github.com/android/ndk/issues/17#issuecomment-401997677
Any other information, logs, or outputs that you want to share?
n/a