How can I link a system library statically in mostly static mode (linkstatic=1)? I tried to use "-Wl,-Bstatic -lboost_thread -Wl,-Bdynamic" or "-Wl,-Bstatic", "-lboost_thread", "-Wl,-Bdynamic", but none of them worked. I don't want to hard code the path of libboost_thread.a in the system.
cc_binary(
name = "main",
srcs = [
"main.cpp",
],
linkopts = [
"-lboost_thread",
],
)
And boost_thread library is linked as a dynamic library.
ldd bazel-bin/main
linux-vdso.so.1
libboost_thread.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.54.0
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
...
In your WORKSPACE file define an external repository...
new_local_repository(
name = "boost_thread",
path = "/usr/lib/x86_64-linux-gnu",
build_file = "boost_thread.BUILD"
)
Create a boost_thread.BUILD file
cc_library(
name = "lib",
srcs = ["libboost_thread.a"],
visibility = ["//visibility:public"],
)
Then in your cc_binary rule add
deps = ["@boost_thread//:lib",],
and throw in a
linkstatic = 1
to be on the safe side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With