newer protoc version check is bogus
Since version 4.22 the protoc --version
returns a x.y
value rather than a x.y.z
version as before.
The protoc
version must match the libprotobuf
used to compile. Unlike common library versioning upper x.y
values are not compatible with x.a.b
versions. This is enforced in the generated code which has both a check on PROTOBUF_VERSION
and a check on PROTOBUF_MIN_PROTOC_VERSION
.
In x.y.z
versions that results in code like (for 3.21.12):
#if PROTOBUF_VERSION < 3021000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
In 'x.y' versions that results in code like (for 22.1):
#if PROTOBUF_VERSION < 4022000
#error "This file was generated by a newer version of protoc which is"
#error "incompatible with your Protocol Buffer headers. Please update"
#error "your headers."
#endif // PROTOBUF_VERSION
#if 4022001 < PROTOBUF_MIN_PROTOC_VERSION
#error "This file was generated by an older version of protoc which is"
#error "incompatible with your Protocol Buffer headers. Please"
#error "regenerate this file with a newer version of protoc."
#endif // PROTOBUF_MIN_PROTOC_VERSION
or starting with 26.x versions:
#if PROTOBUF_VERSION != 5026001
#error "Protobuf C++ gencode is built with an incompatible version of"
#error "Protobuf C++ headers/runtime. See"
#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp"
#endif
Unlike what is suggested by https://protobuf.dev/support/version-support/#cpp, the protoc
version reported is not 21.x
for a 3.21.x
protobuf package.
Here is a summary table of the values for some of the protoc/protobuf versions:
protobuf package | PROTOBUF_VERSION | PROTOBUF_MIN_PROTOC_VERSION check | protoc version | default PROTOBUF_MIN_PROTOC_VERSION | .pc version |
---|---|---|---|---|---|
3.20.3 | 3020000 | 3020003 | 3.20.3 | 3020000 | 3.20.3 |
3.21.1 | 3021000 | 3021001 | 3.21.1 | 3021000 | 3.21.1.0 |
3.21.12 | 3021000 | 3021012 | 3.21.12 | 3021000 | 3.21.12.0 |
22.0 | 4022000 | 4022000 | 22.0 | 4022000 | 4.22.0.0 |
22.1 | 4022000 | 4022001 | 22.1 | 4022000 | 22.1.0 |
23.4 | 4023000 | 4023004 | 23.4 | 4023000 | 23.4.0 |
26.1 | 5026001 | n/a | 26.1 | n/a | 26.1.0 |
28.3 | 5028003 | n/a | 28.3 | n/a | 28.3.0 |
We can use protoc as long as the x.y.z
version is at least or equal to the x.y.z
libprotobuf version. Except we don't know the full value anymore from the package version. This also not true with the 5..y.z
versions which no longer check the protoc
version but only the libprotobuf
is exactly the same version, whereas before it was a minimum.
Right now contribs and autotools check the protoc
version matches exactly the "major.minor.*" version of libprotobuf. This is bogus because a 3.21.1
protoc cannot work with libprotobuf 3.21.12
(while the opposite is possible).
meson uses a different checks. Until 3.21.12 (or before 3.22.0) the protoc version x.y.z
must match exactly the libprotobuf x.y.z
version, which doesn't allow a newer protoc to be used with other libprotobuf. Starting with 3.22.x (or 22.x) the protoc version 'x.y' must match exactly the libprotobuf x.y
version, which doesn't allow using newer a protoc. This the exact/correct check for 26.x and above.
For the record here is a list of protobuf versions in various distros/UNIX systems: [