#893·glog

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

Author: Nick-infinityCreated Feb 11, 2023Updated Feb 21, 2024
LabelsPR welcome

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", )