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
[bazel build] Linking error due to not linking with pthread #176
Comments
Thanks, I've noted this also in #153, but had no time yet to look into how to fix this properly for both OS X (no need for
|
Would you mind sharing the warning that you get on OS X? For librt a POSIX-compliant compiler has to accept -lrt, even if librt is part of libc on a particular system. I'm not sure if it's not also the case for libpthread. If so, we might wish to just stomach the warning for now and file a bug against Clang. |
I'll have a look and will post it. BTW: There's a branch with the fix where I was preparing a PR in my fork. |
Looking at it, I used |
Yes, POSIX specifies that a compiler has to understand http://pubs.opengroup.org/onlinepubs/9699919799//utilities/c99.html (grep for "-l pthread") It also seems that POSIX doesn't say anything about |
Alright, thanks for clarifying. I'll change it to |
This seems to work more reliably across platforms. Actually, both seem to work on Apple platforms, so we probably didn't need the conditions, while Android seems to only accept -pthread, based on [1]. This also matches Abseil [2], Envoy [3], and a random example in Bazel documentation [4]. Though, as a counter-example, POSIX seems to prefer -lpthread, not -pthread, per [5]. [1] grpc/grpc#31938 (comment) [2] https://github.com/abseil/abseil-cpp/blob/625a18016d6208c6c0419697cb6caa3f23ce31bc/absl/base/BUILD.bazel#L185 [3] https://github.com/envoyproxy/envoy/blob/main/bazel/envoy_binary.bzl#L72 [4] https://bazel.build/tutorials/cpp-use-cases#include-external-libraries [5] gflags/gflags#176 (comment) Change-Id: I15005bcf4e4b7ebe91a835b8262c5c6434715c3b Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55927 Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com> Commit-Queue: David Benjamin <davidben@google.com>
This seems to work more reliably across platforms. Actually, both seem to work on Apple platforms, so we probably didn't need the conditions, while Android seems to only accept -pthread, based on [1]. This also matches Abseil [2], Envoy [3], and a random example in Bazel documentation [4]. Though, as a counter-example, POSIX seems to prefer -lpthread, not -pthread, per [5]. [1] grpc/grpc#31938 (comment) [2] https://github.com/abseil/abseil-cpp/blob/625a18016d6208c6c0419697cb6caa3f23ce31bc/absl/base/BUILD.bazel#L185 [3] https://github.com/envoyproxy/envoy/blob/main/bazel/envoy_binary.bzl#L72 [4] https://bazel.build/tutorials/cpp-use-cases#include-external-libraries [5] gflags/gflags#176 (comment) Change-Id: I15005bcf4e4b7ebe91a835b8262c5c6434715c3b Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55927 Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com> Commit-Queue: David Benjamin <davidben@google.com> (cherry picked from commit 412b20b0f699938a370a97cc11815b1eb1e0fcb2)
This seems to work more reliably across platforms. Actually, both seem to work on Apple platforms, so we probably didn't need the conditions, while Android seems to only accept -pthread, based on [1]. This also matches Abseil [2], Envoy [3], and a random example in Bazel documentation [4]. Though, as a counter-example, POSIX seems to prefer -lpthread, not -pthread, per [5]. [1] grpc/grpc#31938 (comment) [2] https://github.com/abseil/abseil-cpp/blob/625a18016d6208c6c0419697cb6caa3f23ce31bc/absl/base/BUILD.bazel#L185 [3] https://github.com/envoyproxy/envoy/blob/main/bazel/envoy_binary.bzl#L72 [4] https://bazel.build/tutorials/cpp-use-cases#include-external-libraries [5] gflags/gflags#176 (comment) Change-Id: I15005bcf4e4b7ebe91a835b8262c5c6434715c3b Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55927 Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com> Commit-Queue: David Benjamin <davidben@google.com> (cherry picked from commit 412b20b0f699938a370a97cc11815b1eb1e0fcb2)
This seems to work more reliably across platforms. Actually, both seem to work on Apple platforms, so we probably didn't need the conditions, while Android seems to only accept -pthread, based on [1]. This also matches Abseil [2], Envoy [3], and a random example in Bazel documentation [4]. Though, as a counter-example, POSIX seems to prefer -lpthread, not -pthread, per [5]. [1] grpc/grpc#31938 (comment) [2] https://github.com/abseil/abseil-cpp/blob/625a18016d6208c6c0419697cb6caa3f23ce31bc/absl/base/BUILD.bazel#L185 [3] https://github.com/envoyproxy/envoy/blob/main/bazel/envoy_binary.bzl#L72 [4] https://bazel.build/tutorials/cpp-use-cases#include-external-libraries [5] gflags/gflags#176 (comment) Change-Id: I15005bcf4e4b7ebe91a835b8262c5c6434715c3b Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/55927 Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Adam Langley <agl@google.com> Commit-Queue: David Benjamin <davidben@google.com> (cherry picked from commit 412b20b0f699938a370a97cc11815b1eb1e0fcb2)
When I compile gflags-example (as well as my own project), I get the following error:
Adding
linkopts = [ "-lpthread" ]
to the binary target I'm compiling works the problem around for me.The text was updated successfully, but these errors were encountered: