-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
go-sqlite3 new_go_repository fails to build #274
Comments
What version of bazel/rules_go are you using?
On linux with bazel 0.4.4 and rules_go 0.4.0 this works for me.
…On Wed, Feb 22, 2017 at 11:05 AM, Sean Fern ***@***.***> wrote:
Expected this to work as of #166
<#166> but getting undefined
pthread references when go-sqlite3 is pointed at the v1.2.0 release commit.
Here's the block in the WORKSPACE:
new_go_repository(
name = 'com_github_mattn_go_sqlite3',
importpath = 'github.com/mattn/go-sqlite3',
commit = 'ca5e3819723d8eeaf170ad510e7da1d6d2e94a08',
)
And here's the error output:
# bazel build --verbose_failures @com_github_mattn_go_sqlite3//:go_default_library
INFO: Found 1 target...
ERROR: /root/.cache/bazel/_bazel_root/8cd13b75700216788cbc2043831c737d/external/com_github_mattn_go_sqlite3/BUILD:5:1: Linking of rule ***@***.***_github_mattn_go_sqlite3//:cgo_default_library.cgo.dir/gen/_cgo_.o' failed: linux-sandbox failed: error executing command
(cd /root/.cache/bazel/_bazel_root/8cd13b75700216788cbc2043831c737d/bazel-sandbox/680b43be-f2a1-4dc6-abff-a2622f463272-0/execroot/app && \
exec env - \
/root/.cache/bazel/_bazel_root/8cd13b75700216788cbc2043831c737d/execroot/app/_bin/linux-sandbox @/root/.cache/bazel/_bazel_root/8cd13b75700216788cbc2043831c737d/bazel-sandbox/680b43be-f2a1-4dc6-abff-a2622f463272-0/linux-sandbox.params -- /usr/bin/gcc -o bazel-out/local-fastbuild/bin/external/com_github_mattn_go_sqlite3/cgo_default_library.cgo.dir/gen/_cgo_.o -Wl,-no-as-needed -B/usr/bin -B/usr/bin -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,-S ***@***.***/local-fastbuild/bin/external/com_github_mattn_go_sqlite3/cgo_default_library.cgo.dir/gen/_cgo_.o-2.params).
bazel-out/local-fastbuild/bin/external/com_github_mattn_go_sqlite3/cgo_default_library.cgo.dir/gen/lib_cgo_lib.lo(sqlite3-binding.pic.o): In function `pthreadMutexAlloc':
sqlite3-binding.c:(.text+0x4162): undefined reference to `pthread_mutexattr_init'
sqlite3-binding.c:(.text+0x4173): undefined reference to `pthread_mutexattr_settype'
sqlite3-binding.c:(.text+0x4192): undefined reference to `pthread_mutexattr_destroy'
bazel-out/local-fastbuild/bin/external/com_github_mattn_go_sqlite3/cgo_default_library.cgo.dir/gen/lib_cgo_lib.lo(sqlite3-binding.pic.o): In function `pthreadMutexTry':
sqlite3-binding.c:(.text+0x425b): undefined reference to `pthread_mutex_trylock'
bazel-out/local-fastbuild/bin/external/com_github_mattn_go_sqlite3/cgo_default_library.cgo.dir/gen/lib_cgo_lib.lo(sqlite3-binding.pic.o): In function `sqlite3ThreadCreate':
sqlite3-binding.c:(.text+0x85c4): undefined reference to `pthread_create'
bazel-out/local-fastbuild/bin/external/com_github_mattn_go_sqlite3/cgo_default_library.cgo.dir/gen/lib_cgo_lib.lo(sqlite3-binding.pic.o): In function `sqlite3ThreadJoin':
sqlite3-binding.c:(.text+0x8659): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Target @com_github_mattn_go_sqlite3//:go_default_library failed to build
INFO: Elapsed time: 0.183s, Critical Path: 0.09s
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#274>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALF-0m0wWZjpCmW0v9magr0vRp5Bw2K2ks5rfFyxgaJpZM4MI1me>
.
|
I was able to reproduce this with Bazel 0.4.4 and rules_go both at HEAD and 0.4.0. I'm building from Goobuntu 14.04. @pmbethe09, are you building on a different platform? I worked around this by checking out go-sqlite3 directly, generating a BUILD file with gazelle, then manually adding "-pthread" to "clinkopts" of ":cgo_default_library". It looks like Gazelle generates clinkopts by taking go/build.Package.CgoLDFLAGS. I didn't see "-pthread" anywhere in the "#cgo LDFLAGS" comments of that library. Maybe it should be in there? I don't know how Gazelle would infer this on its own. |
I was able to fix this in my local rules_go by doing this. I didn't have the time to investigate upstreaming it yet but this seems like a good time to point out that it works when that flag is added. |
I looked into this a bit further. "go build" always adds "-mthreads" (for Windows) or "-pthread" (everything else) to the command line if Cgo is enabled. There is no need for Cgo or Gazelle to infer this flag. We should just add these to the default link options, as @achew22 mentioned. I'll put together a PR to fix this. |
This matches behavior of "go build", which compiles and links C code with -pthread (or -mthreads on Windows). Fixes bazel-contrib#274
Expected this to work as of #166 but getting undefined pthread references when go-sqlite3 is pointed at the v1.2.0 release commit. Here's the block in the WORKSPACE:
And here's the error output:
The text was updated successfully, but these errors were encountered: