Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nick-infinity opened this issue Feb 11, 2023 · 2 comments
Open

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

Nick-infinity opened this issue Feb 11, 2023 · 2 comments
Assignees

Comments

@Nick-infinity
Copy link

Nick-infinity commented Feb 11, 2023

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

@drigz
Copy link
Member

drigz commented Feb 23, 2023

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:

final_lib_copts = select({

@jiabei-dm
Copy link

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants