Should protoc v2.6.1 produce 'Expected "required", "optional", or "repeated".'

4.7k views Asked by At

Using Ubuntu 16.04 and CMake, I'm trying to create a shared library from the protobuf files. CMakes protobuf_generate_cpp is producing PROTO_SRCS and PROTO_HDRS.

I didn't have any google/protobuf/*.proto files on my system, so I downloaded 3.6.1 and moved these into /usr/local/include. I know I'm using proto2 and protoc is version 2, and some of those *.proto files in 3.6.1 are proto3, but the files below (the ones I'm making use of are syntax="proto2"), so I think this should be ok.

However, I'm running into the following error.

 $ 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.

Anyone have thoughts?

1

There are 1 answers

0
Marc Gravell On BEST ANSWER

Recent versions of descriptor.proto declare reserved fields - as an example line 439. This is a new syntax that was back-ported to proto2 syntax, but old versions of protoc won't understand it (understably). Either update protoc, or use the descriptor.proto that came with the protoc you are using.