I'm encountering an error when trying to build my C++ project. The error message reads: "Protobuf C++ gencode is built with an incompatible version of."
Both gRPC and Protobuf are on the latest version:
brew info grpc
==> grpc: stable 1.62.2 (bottled), HEAD
brew info protobuf
==> protobuf: stable 26.1 (bottled)
Protobuf files are built using cmake:
set(_GRPC_GRPCPP gRPC::grpc++)
if(CMAKE_CROSSCOMPILING)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
endif()
# Gets the protos file path
get_filename_component(PROTO_FILE "./proto/proto.proto" ABSOLUTE)
get_filename_component(PROTO_FILE_PATH "${PROTO_FILE}" PATH)
# Sets the location for generated files
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/generated/)
set(PROTO_SOURCES "${CMAKE_BINARY_DIR}/generated/proto.pb.cc")
set(PROTO_HEADERS "${CMAKE_BINARY_DIR}/generated/proto.pb.h")
set(GRPC_SOURCES "${CMAKE_BINARY_DIR}/generated/proto.grpc.pb.cc")
set(GRPC_HEADERS "${CMAKE_BINARY_DIR}/generated/proto.grpc.pb.h")
set_property(SOURCE ${GRPC_SOURCES} ${PROTO_SOURCES} ${GRPC_HEADERS} ${PROTO_HEADERS} PROPERTY SKIP_AUTOMOC ON)
# Generate *.pb.* and *.qrpc.* files from .proto file
add_custom_command (
OUTPUT "${PROTO_SOURCES}" "${PROTO_HEADERS}" "${GRPC_SOURCES}" "${GRPC_HEADERS}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_BINARY_DIR}/generated/"
--cpp_out "${CMAKE_BINARY_DIR}/generated/"
-I "${PROTO_FILE_PATH}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${PROTO_FILE}"
DEPENDS "${PROTO_FILE}"
)
I reinstalled both packages but nothing seems to work. I tried uninstalling abseil too, but nope.
brew uninstall --ignore-dependencies --force grpc opencv protobuf abseil
brew cleanup
brew autoremove
brew install grpc opencv
This error is emitted from the #ifdef
near the beginning of the generated .pb.h
file:
// Generated by the protocol buffer compiler. DO NOT EDIT!
...
// Protobuf C++ Version: 5.28.0-dev
...
#include "google/protobuf/runtime_version.h"
#if PROTOBUF_VERSION != 5026000
#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
The PROTOBUF_VERSION
define comes from runtime_version.h
, while the 5026000
value it is compared against is written by protoc when it generates the file.
To debug the issue, first verify that the generated .pb.h
file contains the version number you expect. If it does not, your build process is using a different version of protoc
. Search your path for other installed versions using whereis protoc
.
If the generated .pb.h
version is correct, then the problem is in the included runtime_version.h
. Instruct the compiler to show full path of the included files. For GCC and clang this can be done using the -H
command line switch. Then when you discover the outdated installation, either uninstall it or adjust your include path to ignore it.