可以bazel构建DLL吗?

时间:2018-04-05 05:00:38

标签: c++ tensorflow dll bazel

我已经尝试使用bazel编译DLL了好几天。 我按照示例bazel build希望生成DLL。 我使用的BUILD文件如下:

cc_binary(
    name = "expdtctlib",
    srcs = ["expdtctlib.cpp"],

    deps = [
        "//tensorflow/core:tensorflow",
    ],
    linkshared = 1,
)

cc_binary(
    name = "expdetect",
    srcs = ["expdetect.cpp"],
    data = [":expdtctlib.dll"],
    deps = [
        "//tensorflow/core:tensorflow",
    ],
)

我跑了命令:

bazel build :expdetect

但错误表示“expdtctlib.dll”丢失了。 不要先bazel生成“expdtctlib.dll”然后编译“expdetect.cpp”?

此外,我尝试使用另一种方法来构建DLL。BUILD文件如下:

cc_library(
    name = "ExpDetector",
    srcs = ["ExpDetector.cc"],
    hdrs = ["ExpDetector.h"],
    deps = [
        "//tensorflow/core:tensorflow",
    ],
)

cc_binary(
    name = "expdetect",
    srcs = ["expdetect.cc"],
    deps = [
        "//tensorflow/core:tensorflow",
        ":ExpDetector",
    ],
)

经过长时间的编译,虽然输出了EXE文件并运行良好,但我只能找到.lib和.exp文件,但是.dll文件。

有没有人使用bazel成功构建DLL?我需要你的帮助。

1 个答案:

答案 0 :(得分:0)

我修改了两个BUILD文件如下,它运行良好!

filegroup(
    name = "srcs",
    srcs = glob(["**"]),
    visibility = ["//examples:__pkg__"],
)


cc_binary(
    name = "expdtctlib.dll",
    srcs = ["expdtctlib.cc",
            "expdtctlib.h"],

    deps = [
        "//tensorflow/core:tensorflow",
    ],
    linkshared = 1,
)

cc_binary(
    name = "expdetect",
    srcs = ["expdetect.cc"],
    data = [":expdtctlib.dll"],
    deps = [
        "//tensorflow/core:tensorflow",
    ],
)

下面的一个是“// tensorflow”。

exports_files(
    [
        "LICENSE",
        "ACKNOWLEDGEMENTS",
    ],
)

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "srcs",
    srcs = glob(["**"]) + [
        "//tensorflow/tensorflow/detector0405:srcs",
    ],
)

我不熟悉bazel和c ++,但这些修改工作。我会阅读Bazel Document以了解更多信息。