简体   繁体   English

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

[英]Are linker flags (linkopts) propagats in Bazel?

I'm building an Android library based on Tensorflow with Bazel. 我正在使用Bazel构建基于Tensorflow的Android库。

Here the BUILD file 这是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",
    ],
)

The linker complains about not finding -lpthread , while I didn't add this flag to linkopts . 链接器抱怨找不到-lpthread ,而我没有将此标志添加到linkopts

I've checked the executed command, and in fact there is extra flags on it: -lz -lpthread ... 我已经检查了执行的命令,实际上上面有额外的标志: -lz -lpthread ...

Where did they came from ? 他们来自哪里? Is there a workaround for this ? 是否有解决方法?

I got the answer from the tensorflow's issue tracker. 我从tensorflow的问题跟踪器获得了答案。

@jart @jart

Since copts and linkopts are viral and propagate to dependencies, -lpthread is most likely being inherited from @boringssl//:crypto 由于copts和linkopts具有病毒性并传播到依赖项,因此-lpthread最有可能是从@boringssl //:crypto继承的

@andrewharp @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: -lpthread在Android上不是必需的或不可能的,因此听起来解决方案是为select语句添加另一个条件,如链接的提交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. 我知道的唯一其他解决方法是,无需编辑其他存储库就是创建一个虚拟的libpthread.so目标,但这确实很麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM