在bazel / tensorflow构建期间如何动态链接外部共享库

时间:2019-07-09 12:54:33

标签: tensorflow bazel

我试图将TensorFlow与我自己的共享库链接,并调用我在TF中开发的功能。

我有一个名为liba.so的库,函数名称为funa(),我将该库及其头文件放在了third_party/myownlib中,在tensorflow/core/framework/中修改了源代码

因此,我在How to add external header files during bazel/tensorflow build之后,通过

third_party/myownlib中创建了BUILD文件。
cc_library(
    name = "liba",
    hdrs = glob(["liba.h",]),
    srcs = glob(["liba.so"]),
    visibility = ["//visibility:public"],
)

并通过以下更改编辑了tensorflow/core/中的BUILD文件:

    name = "framework_internal_impl",
    ...
    copts = tf_copts() + ["-Ithird_party/myownlib"],
    linkopts = ["-la"] + select({
        "//tensorflow:freebsd": ["-lm"],
        "//tensorflow:windows": [],
        "//conditions:default": [
            "-ldl",
            "-lm",
        ],
    }),
    deps = [

        "//third_party/myownlib:liba",
    ] + if_static(
        extra_deps = ["@protobuf_archive//:protobuf"],
        otherwise = ["@protobuf_archive//:protobuf_headers"],
    ) + mkl_deps(),
    alwayslink = 1,
)

但是我最终得到了/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/tensorflow/contrib/framework/gen_gen_variable_ops_py_wrappers_cc , '\'''\'' 0 0 > bazel-out/k8-opt/genfiles/tensorflow/contrib/framework/python/ops/gen_variable_ops.py') bazel-out/host/bin/tensorflow/contrib/framework/gen_gen_variable_ops_py_wrappers_cc: error while loading shared libraries: liba.so: cannot open shared object file: No such file or directory

我正在使用bazel 0.16.1和TF 1.11.0。

0 个答案:

没有答案