flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

C++ code generated with `flatc --grpc` requires Protobuf to be installed

Open frankkusters opened this issue 3 years ago • 0 comments

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.h includes grpcpp/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> in greeter.grpc.fb.h results in successful compilation. That does mean the generated code needs to be edited.
  • Since these headers are part of libprotobuf-dev, installing libprotobuf-dev also works around the issue. Unfortunately this complicates our installation process.

frankkusters avatar Oct 13 '22 11:10 frankkusters