链接器标志 (linkopts) 是否在 Bazel 中传播?

Are linker flags (linkopts) propagats in Bazel?

我正在使用 Bazel 基于 Tensorflow 构建 Android 库。

这里是 BUILD 文件

cc_binary(
    name = "libfoo.so",
    srcs = glob([
         "jni/**/*.cc",
         "jni/**/*.h",
    ]),
    copts = [ "-fexceptions", "-DEIGEN_AVOID_STL_ARRAY",
              "-mfpu=neon", "-std=c++11",
              "-DMIN_LOG_LEVEL=0", "-DTF_LEAN_BINARY",
              "-O2", ],
    linkopts = [
        "-llog",
        "-lm",
    ],
    linkshared = 1,
    deps = [
        "@org_tensorflow//tensorflow/core:android_tensorflow_lib",
        "@boringssl//:crypto",
    ],
)

链接器抱怨找不到 -lpthread,而我没有将此标志添加到 linkopts

我检查了执行的命令,实际上上面有额外的标志:-lz -lpthread ...

他们从哪里来?有解决办法吗?

我从 tensorflow 的问题跟踪器中得到了答案。

@jart

Since copts and linkopts are viral and propagate to dependencies, -lpthread is most likely being inherited from @boringssl//:crypto

@andrewharp

-lpthread is not necessary or possible on Android, so it sounds like the solution would be to add another condition for the select statement as in the linked commit google/protobuf#1386:

...

The only other workaround I know of that doesn't require editing the other repository is to create a dummy libpthread.so target, but that's pretty hacky.