automatically including .pb.h files we depend on

39 views
Skip to first unread message

Alejandro Mery

unread,
Nov 6, 2023, 1:49:00 PM11/6/23
to nanopb
hi, I'm getting started trying to use nanopb for rpc between an embedded C application and a Go application.

I'm using `nanopb_generator -C` from the latest master, but the generated foo.pb.c on includes foo.pb.h, and that .h only includes pb.h itself. what's the correct way of getting the .pb.c to include the .pb.h files that define the types/structs we depend on?

`nanopb_generator -C nanopb.proto` itself produces a .pb.c that can't find `google_protobuf_field_descriptor_proto_type_t` as no where `google/protobuf/descriptor.pb.h` is included.

also, is there a way if specifying a prefix for those includes? it seem one can only customize pb.h include.

thanks in advance,
Alejandro Mery

Alejandro Mery

unread,
Nov 6, 2023, 1:53:43 PM11/6/23
to nanopb
apologies for the self-reply.

On Monday, 6 November 2023 at 18:49:00 UTC Alejandro Mery wrote:
also, is there a way if specifying a prefix for those includes? it seem one can only customize pb.h include.

please disregard this part, `-Q` does that, but still only of the direct dependency


Petteri Aimonen

unread,
Nov 6, 2023, 2:00:21 PM11/6/23
to nan...@googlegroups.com
Hi,

> `nanopb_generator -C nanopb.proto` itself produces a .pb.c that can't find
> `google_protobuf_field_descriptor_proto_type_t` as no where
> `google/protobuf/descriptor.pb.h` is included.

Normally all imported .proto files generate corresponding includes of .pb.h files.

There are two proto files that are on default exclusion list, because
usually there is no need to include nanopb.proto or descriptor.proto in
the compiled C code, even though they are needed by protoc.

Custom includes of those or other files can be added by adding this near
the beginning of a .proto (or equivalently in .options file or -s on
command line):

option (nanopb_fileopt).include = 'foobar.h';

--
Petteri

Alejandro Mery

unread,
Nov 6, 2023, 2:56:03 PM11/6/23
to nanopb
On Monday, 6 November 2023 at 19:00:21 UTC Petteri Aimonen wrote:
Hi,

> `nanopb_generator -C nanopb.proto` itself produces a .pb.c that can't find
> `google_protobuf_field_descriptor_proto_type_t` as no where
> `google/protobuf/descriptor.pb.h` is included.

Normally all imported .proto files generate corresponding includes of .pb.h files.

There are two proto files that are on default exclusion list, because
usually there is no need to include nanopb.proto or descriptor.proto in
the compiled C code, even though they are needed by protoc.

excellent, it all makes much more sense now
 
Custom includes of those or other files can be added by adding this near
the beginning of a .proto (or equivalently in .options file or -s on
command line):

option (nanopb_fileopt).include = 'foobar.h';

would you know the notation for fileopts on the options file? 

Petteri Aimonen

unread,
Nov 7, 2023, 12:59:19 AM11/7/23
to nan...@googlegroups.com
Hi,

> would you know the notation for fileopts on the options file?

* include:"foobar.h"

in place of wildcard you can also specify the proto file name.
Example e.g. here:
https://github.com/nanopb/nanopb/blob/master/examples/network_server/fileproto.options

--
Petteri
Reply all
Reply to author
Forward
0 new messages