glog icon indicating copy to clipboard operation
glog copied to clipboard

Can not find -lpthread for android ndk arm64-v8a build

Open Nick-infinity opened this issue 3 years ago • 2 comments

Hello, I am trying to build bazel/example:main with ndk r25 tool chain for android api level 31 . I am using bazel version 6.0.0 . When I try to compile the the target I get linker error for pthread library. In my understanding ndk does not have a separate pthread library. I am suspecting : https://github.com/google/glog/blob/f545ff5e7d7f3df95f6e86c8cb987d9d9d4bd481/bazel/glog.bzl#L73 and https://github.com/google/glog/blob/f545ff5e7d7f3df95f6e86c8cb987d9d9d4bd481/src/config.h.cmake.in#L34

Are there any specific instructions to build for android using ndk for bazel ? Please guide me on how to fix this issue if it has been seen earlier. @sergiud

I have added .bazelrc file in the root of this project in parallel to WORKSPACE file to allow ndk build configuration

build:android --crosstool_top=//external:android/crosstool build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

build:android_arm --config=android build:android_arm --cpu=armeabi-v7a build:android_arm --fat_apk_cpu=armeabi-v7a

build:android_arm64 --config=android build:android_arm64 --cpu=arm64-v8a build:android_arm64 --fat_apk_cpu=arm64-v8a

build:android_x86 --config=android build:android_x86 --cpu=x86 build:android_x86 --fat_apk_cpu=x86

build:android_x86_64 --config=android build:android_x86_64 --cpu=x86_64 build:android_x86_64 --fat_apk_cpu=x86_64

build --fat_apk_cpu=x86_64,arm64-v8a,armeabi-v7a build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain build --experimental_repo_remote_exec test --fat_apk_cpu=x86_64,arm64-v8a,armeabi-v7a test --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

build --spawn_strategy=standalone

I have also appended code to workspace file to accomodate ndk rules like this :

android_sdk_repository( name = "androidsdk", api_level = 31, )

android_ndk_repository( name = "androidndk", )

Nick-infinity avatar Feb 11 '23 19:02 Nick-infinity

Are there any specific instructions to build for android using ndk for bazel ?

No, I'm not sure if anybody has tried that and can't see any issues referencing it.

If you can work out how to break the dependency on pthread, please send a PR to change glog.bzl to use appropriate cflags on Android: https://github.com/google/glog/blob/f545ff5e7d7f3df95f6e86c8cb987d9d9d4bd481/bazel/glog.bzl#L145

drigz avatar Feb 23 '23 08:02 drigz

This is because glog depends on "@com_github_gflags_gflags//:gflags" which links pthread. Instead, Android targets should depend on "@com_github_gflags_gflags//:gflags_nothreads".

jiabei-dm avatar Feb 21 '24 21:02 jiabei-dm