-1

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.

asked Apr 10, 2025 at 18:34
1
  • 1
    @drescherjm That appears to be an error itself. edition is not compatiable with syntax, according to the documentation. I have tried it, but adding either option made no difference. Commented Apr 10, 2025 at 18:58

1 Answer 1

0

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.

answered Apr 14, 2025 at 17:38
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.