代码之家  ›  专栏  ›  技术社区  ›  Ender

Protoc 2.6.1是否应生成“预期”的“必需”、“可选”或“重复”。

  •  1
  • Ender  · 技术社区  · 5 年前

    使用Ubuntu16.04和cmake,我试图从protobuf文件创建一个共享库。cmakes protobuf_generate_cpp正在生成proto_srcs和proto_hdrs。

    我的系统中没有任何google/protobuf/*.proto文件,所以我下载了3.6.1并将其移动到/usr/local/include中。我知道我使用的是proto2,protoc是版本2,3.6.1中的一些*.proto文件是proto3,但是下面的文件(我使用的是syntax=“proto2”),所以我认为应该可以。

    但是,我遇到了以下错误。

     $ protoc --version
    libprotoc 2.6.1
    
    [  2%] Running C++ protocol buffer compiler on models.proto
    google/protobuf/descriptor.proto:439:3: Expected "required", "optional", or "repeated".
    google/protobuf/descriptor.proto:439:12: Expected field name.
    google/protobuf/descriptor.proto:497:3: Expected "required", "optional", or "repeated".
    google/protobuf/descriptor.proto:497:12: Expected field name.
    google/protobuf/descriptor.proto:498:3: Expected "required", "optional", or "repeated".
    google/protobuf/descriptor.proto:498:12: Expected field name.
    google/protobuf/descriptor.proto:597:3: Expected "required", "optional", or "repeated".
    google/protobuf/descriptor.proto:597:12: Expected field name.
    google/protobuf/descriptor.proto:620:3: Expected "required", "optional", or "repeated".
    google/protobuf/descriptor.proto:620:12: Expected field name.
    edk/edk_extensions.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
    edk/edk_extensions.proto:15:8: ".google.protobuf.FieldOptions" is not defined.
    edk/edk_extensions.proto:20:8: ".google.protobuf.MessageOptions" is not defined.
    models.proto: Import "edk/edk_extensions.proto" was not found or had errors.
    

    有人有想法吗?

    1 回复  |  直到 5 年前
        1
  •  2
  •   Marc Gravell    5 年前

    descriptor.proto声明的最新版本 reserved fields -作为一个例子 line 439 .这是一种新的语法,它被重新移植到Proto2语法,但是Protoc的旧版本无法理解它(可以理解)。要么更新protoc,要么使用您使用的protoc附带的descriptor.proto。