首页 > 解决方案 > protoc v2.6.1 是否应该产生“预期的“必需”、“可选”或“重复”。

问题描述

使用 Ubuntu 16.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.

有人有想法吗?

标签: cmakeprotocol-buffersprotocproto3

解决方案


最新版本的 descriptor.proto 声明了保留字段——例如第 439 行。这是一种向后移植到 proto2 语法的新语法,但旧版本的 protoc 无法理解它(很不稳定)。要么更新 protoc,要么使用你正在使用的 protoc 附带的 descriptor.proto。


推荐阅读