I am trying to compile the following .proto file:
edition = "2023";
package example_proto;
import "google/protobuf/cpp_features.proto";
message BidAsk {
required double bid = 1;
required double ask = 2;
required string timestamp = 3 [features.(pb.cpp).string_type = VIEW];
}
As far as I am aware, this matches the requirements specified in this documentation page.
I am aware that required is not usually recommended, however in this case it does not make sense to have a BidAsk message without all of the fields populated, and this message will never change or be extended.
When I run protoc on this file, I get the following error.
$ protoc bid_ask.proto --cpp_out=test
[libprotobuf WARNING google/protobuf/compiler/parser.cc:646] No syntax specified for the proto file: bid_ask.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
bid_ask.proto:1:1: Expected top-level statement (e.g. "message").
Update: I think this is caused by an out-of-date protobuf compiler.
$ protoc --version
libprotoc 3.21.12
I think this is too old to support the edition syntax.
This is a bit surprising since I installed protoc via apt install protobuf-compiler. The host OS is Ubuntu 24.10, which is quite recent. I'm not sure why the version of protoc supplied via the package manager is so old.
I will ask a seperate question about how to update it.
1 Answer 1
I have now confirmed that the issue was caused by an out-of-date protoc and protobuf development libraries.
Ubuntu 24.10 ships with a version of the protobuf development libs which does not support this more recent protobuf syntax.
To solve the issue, I used a combination of vcpkg with my C++ project to obtain access to a more recent version of the protobuf dev libs.
editionis not compatiable withsyntax, according to the documentation. I have tried it, but adding either option made no difference.