【问题标题】:bazel tensorflow protoc version mismatchbazel tensorflow protoc 版本不匹配
【发布时间】:2019-08-12 21:34:27
【问题描述】:

我尝试在 tensorflow r1.12.0(gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC))中的 bazel 中构建自定义协议缓冲区,但一直遇到以下错误消息

这个文件是由新版本的 protoc 生成的,它是 与您的协议缓冲区标头不兼容。请更新您的 标题。

仔细检查了上述错误的原因,我直接查看了bazel-genfiles,发现对于预先存在的pb.h文件,例如examples.pb.h,硬编码的bazel版本是3.6.0 :

#if GOOGLE_PROTOBUF_VERSION < 3006000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please update
#error your headers.
#endif
#if 3006000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please
#error regenerate this file with a newer version of protoc.
#endif

但是对于我自己自定义protocol buffer的pb.h文件,显示的是3.5版本:

#if GOOGLE_PROTOBUF_VERSION < 3005000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please update
#error your headers.
#endif
#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please
#error regenerate this file with a newer version of protoc.
#endif

因此不兼容。

确实,如果我通过这样的 cc_proto_library 规则自己构建 examples.proto,

cc_proto_library(
    name = "example_cc_protos",
    deps = [":example_protos"],
)

我还在生成的examples.pb.h文件中看到版本号3005000,所以上面的3006000 pb.h文件可能是从远程源下载的。

我的 pip/protobuf 显示 3.6.1 版本,protoc --version 也显示 3.6.1,所以我怀疑 bazel 本身的 protobuf 必须是 3.5 版本,导致上面不幸的硬编码 3005000。

我发现 protobuf 3.6.1 从bazel 0.17 开始可用; similar link for bazel 0.16 给了我一个 404。因此我尝试使用 GitHub 上的预构建安装程序安装 bazel 0.17。但令人惊讶的是,生成的 pb.h 文件仍然有 3005000 原始版本硬编码。

然后我尝试通过

从源代码构建 bazel
git clone https://github.com/bazelbuild/bazel.git
cd bazel
bazel build //src:bazel
alias bazel=bazel-bin/src/bazel

但这仍然给了我同样的错误。

我也尝试过多个版本的 bazel,从 0.15.x 到 0.18.x;更高版本无法构建tensorflow_model_server,所以我没有尝试。对于从 cc_proto_library bazel 规则构建的 pb.h,它们都产生 3005000。

官方 tensorflow 文档说 tf 1.12 用 bazel 0.15 进行了测试:

最后,如果我直接用 protoc 构建 .proto 文件,我确实在 pb.h 文件中得到 3006001,只是为了表明我正确安装了 protoc。

我的问题是 pb.h 文件中的 3005000 是从哪里来的?是 gcc、bazel、tensorflow、protoc 还是 pip/protobuf ?

【问题讨论】:

    标签: tensorflow bazel protoc


    【解决方案1】:

    已通过从 张量流/工作空间文件:

    # load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
    
    # closure_repositories()
    

    原因是closure_repositories 使用protobuf 3.5,因为3.6 需要g++11,这不是普遍可用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 2016-12-09
      相关资源
      最近更新 更多