-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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
-lpthread in BUILD breaks Android projects that depend on protobuf #1373
Comments
You should be able to use bazel selectors to selectively include "-lpthread" on non android platforms. See an example of the selector: You probably need to contact the bazel guys about how to select on android though. |
The problem isn't how to include "-lpthread" for non-Android -- we don't need to do anything for this. The question is how can we negate the "-lpthread" in protobuf/BUILD? It seems like this requires an edit to the protobuf source. I am not aware of any way to do this in the dependent project unfortunately. Are there any examples of other Android projects that build with Bazel and use protobuf that you know of? |
The comment there says "Bazel should provide portable link_opts for pthread". It's not clear to me if this is a TODO, or a note to users about how to build for mobile. Googling "bazel portable link_opts" just takes me back to that file. |
What I am proposing is:
though I don't know how to select android in bazel. |
Ah, gotcha (I'd thought you were talking about modifying Tensorflow somehow). We select for Android in Tensorflow like this. //tensorflow:android is defined here. There may be a better way to do it, but if nothing else we could just copy that config_setting into protobuf/BUILD and select against it when defining LINK_OPTS. Happy to do this myself if it sounds good with you. |
Fixed by #1386 |
The android libc, bionic, provides built-in support for pthreads, so no additional linking is necessary. Leaving -pthread breaks the build, see protocolbuffers/protobuf#1373
The android libc, bionic, provides built-in support for pthreads, so no additional linking is necessary. Leaving -pthread breaks the build, see protocolbuffers/protobuf#1373
The android libc, bionic, provides built-in support for pthreads, so no additional linking is necessary. Leaving -pthread breaks the build, see protocolbuffers/protobuf#1373
Hi,
Android supports pthreads, but does not provide a libpthread.so library to link against. The functionality is provided in other system libraries.
Since protobuf/BUILD specifies "-lpthread", I've had to add some hacks to get around this to get the Android Tensorflow demo working by creating a dummy pthread library, which is "linked" against and bundled in the APK: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/BUILD
Now that I'm trying to make a standalone Android executable it's becoming even more problematic as the binary expects to find the fake libpthread.so lib somewhere on its library path.
Is there a better way to build protobuf for Android? Or can the -lpthread flag be made selective on build platform, so that these workarounds are not necessary?
thanks!
The text was updated successfully, but these errors were encountered: