flatbuffers
flatbuffers copied to clipboard
C++ code generated with `flatc --grpc` requires Protobuf to be installed
Steps to reproduce
I'm running Ubuntu and installed libflatbuffers-dev and libgrpc++-dev. My Ubuntu version is 20.04, gRPC 1.16.1, Flatbuffers 1.11.0, although the problem should appear on all current Ubuntu and Debian versions, and on Flatbuffers 22.9.29.
$ cd grpc/samples/greeter
$ flatc --cpp --grpc greeter.fbs
$ g++ -c greeter.grpc.fb.cc # this should generate greeter.grpc.fb.o
In file included from /usr/include/grpcpp/impl/codegen/proto_utils.h:28,
from /usr/include/grpc++/impl/codegen/proto_utils.h:26,
from greeter.grpc.fb.h:13,
from greeter.grpc.fb.cc:6:
/usr/include/grpcpp/impl/codegen/config_protobuf.h:25:10: fatal error: google/protobuf/stubs/common.h: No such file or directory
25 | #include <google/protobuf/stubs/common.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
This is surprising, because Protobuf is not used when using Flatbuffers.
Cause
-
greeter.grpc.fb.hincludesgrpcpp/impl/codegen/proto_utils.h. - That file in turn includes
grpcpp/impl/codegen/config_protobuf.h. - That file then includes headers from
google/protobuf.
The symbols defined through proto_utils.h are not used. The line is put there by the grpc cpp generator: https://github.com/google/flatbuffers/blob/v22.9.29/grpc/src/compiler/cpp_generator.cc#L113
Known workarounds
- Commenting out
#include <grpc++/impl/codegen/proto_utils.h>ingreeter.grpc.fb.hresults in successful compilation. That does mean the generated code needs to be edited. - Since these headers are part of
libprotobuf-dev, installinglibprotobuf-devalso works around the issue. Unfortunately this complicates our installation process.