如何在大多数静态模式(linkstatic = 1)中静态链接系统库?我试图使用“-Wl,-Bstatic -lboost_thread -Wl,-Bdynamic”或“-Wl,-Bstatic”,“ - lboost_thread”,“ - WI,-Bdynamic”,但它们都没有奏效。我不想硬编码系统中libboost_thread.a的路径。
cc_binary(
name = "main",
srcs = [
"main.cpp",
],
linkopts = [
"-lboost_thread",
],
)
boost_thread库作为动态库链接。
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
...
答案 0 :(得分:2)
在您的WORKSPACE文件中定义外部存储库...
Control
创建boost_thread.BUILD文件
new_local_repository(
name = "boost_thread",
path = "/usr/lib/x86_64-linux-gnu",
build_file = "boost_thread.BUILD"
)
然后在cc_binary规则中添加
cc_library(
name = "lib",
srcs = ["libboost_thread.a"],
visibility = ["//visibility:public"],
)
并投入
deps = ["@boost_thread//:lib",],
安全起见。
答案 1 :(得分:0)
基于此问题的答案,Telling gcc directly to link a library statically, "-l:libboost_thread.a" 将静态链接系统库,无需硬编码 libboost_thread.a 在系统中的路径。
cc_binary(
name = "main",
srcs = [
"main.cpp",
],
linkopts = [
"-l:libboost_thread.a",
"-l:libboost_system.a",
],
)