Skip to content

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

Open
@Nick-infinity

Description

@Nick-infinity

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 :

"-DHAVE_PTHREAD",

and
/* Define to 1 if you have the `pthread' library (-lpthread). */

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions