Compiling multiple files

35 views
Skip to first unread message

Alexis Lecoq

unread,
May 13, 2025, 4:48:34 AMMay 13
to nanopb
Hi,
I do not find how can I compile multiple files at once. 
I have this architecture :
/protobuff/
              1st.proto
              2nd.proto
              3rd.proto
              drivers/
                         driver1.proto
                         driver2.proto

1st.proto is importing 2nd, 3rd, and driver1
2nd is importing driver1
3rd is importing driver1 and driver2

I'm trying to compile using this command :
generator-bin\nanopb_generator .\protobuff\1st.proto

but getting not found errors for each import:
protobuff/1st.proto:8:1: Import "2nd.proto" was not found or had errors.
protobuff/1st.proto:9:1: Import "3rd.proto" was not found or had errors.
protobuff/1st.proto:11:1: Import "drivers/driver1.proto" was not found or had errors.
etc...

I guess that's not the right way to compile it ?

A second annoying thing I encounter is that I need to duplicate each proto file because for nanopb to output C code for a byte array for example :
optional bytes EPC = 2 [(nanopb).max_size = 24];
We need to specify the max_size like this.
The thing is that when trying to compile the same file with protoc to output java code, it does not compile due to this. 

Petteri Aimonen

unread,
May 13, 2025, 5:49:45 AMMay 13
to nan...@googlegroups.com
Hi,

You need to define the include path with -I, for example:
generator-bin\nanopb_generator -I protobuff .\protobuff\1st.proto
By default it looks for included files in the current directory.

You can define options in a separate .options file.
This way the Java compiler doesn't see them.
You can wildcards to specify e.g. "*.EPC max_size:24" if you have a lot of similar fields.
Refer to:
https://jpa.kapsi.fi/nanopb/docs/reference.html#defining-the-options-in-a-.options-file
https://github.com/nanopb/nanopb/blob/master/examples/network_server/fileproto.options

--
Petteri
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b-8b12-5f677f4f3da0n%40googlegroups.com.
> --
> You received this message because you are subscribed to the Google
> Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [1]nanopb+un...@googlegroups.com.
> To view this discussion visit
> [2]https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b-8b12-5f6
> 77f4f3da0n%40googlegroups.com.
>
> References
>
> 1. mailto:nanopb+un...@googlegroups.com
> 2. https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b...@googlegroups.com?utm_medium=email&utm_source=footer


Alexis Lecoq

unread,
May 19, 2025, 4:06:38 AMMay 19
to nanopb
Thanks ! But how to include the ones in "drivers" then ?

I tried using this command :

generator-bin\nanopb_generator -I .\protobuff -I .\protobuff\drivers\ .\protobuff\*.proto .\protobuff\drivers\*.proto

It finds all the files under "protobuff" but it does not manage to find the files under "drivers"

Thanks.

Petteri Aimonen

unread,
May 19, 2025, 4:13:04 AMMay 19
to nan...@googlegroups.com
Hi,

To me it seems like that command should work.

The include path is directly passed to protoc, so the same include
path setup should work as you are using with the Java protoc.

--
Petteri
> > <https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b...@googlegroups.com?utm_medium=email&utm_source=footer>
> >
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/nanopb/22e6d7e8-3cda-4756-bfe1-9ba72d134267n%40googlegroups.com.

> Thanks ! But how to include the ones in "drivers" then ?
>
> I tried using this command :
> generator-bin\nanopb_generator -I .\protobuff -I .\protobuff\drivers\
> .\protobuff\*.proto .\protobuff\drivers\*.proto
>
> It finds all the files under "protobuff" but it does not manage to find
> the files under "drivers"
>
> Thanks.
>
> Le mardi 13 mai 2025 à 11:49:45 UTC+2, Petteri Aimonen a écrit :
>
> Hi,
> You need to define the include path with -I, for example:
> generator-bin\nanopb_generator -I protobuff .\protobuff\1st.proto
> By default it looks for included files in the current directory.
> You can define options in a separate .options file.
> This way the Java compiler doesn't see them.
> You can wildcards to specify e.g. "*.EPC max_size:24" if you have a
> lot of similar fields.
> Refer to:
> [1]https://jpa.kapsi.fi/nanopb/docs/reference.html#defining-the-opti
> ons-in-a-.options-file
> [2]https://github.com/nanopb/nanopb/blob/master/examples/network_ser
> send an email to [3]nanopb+un...@googlegroups.com.
> > To view this discussion visit
> [4]https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b-8b12-
> > an email to [1][5]nanopb+un...@googlegroups.com.
> > To view this discussion visit
> >
> [2][6]https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b-8b
> 12-5f6
> > 77f4f3da0n%[7]40googlegroups.com.
> >
> > References
> >
> > 1. mailto:[8]nanopb+un...@googlegroups.com
> > 2.
> [9]https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b...@go
> oglegroups.com?utm_medium=email&utm_source=footer
>
> --
> You received this message because you are subscribed to the Google
> Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [10]nanopb+un...@googlegroups.com.
> To view this discussion visit
> [11]https://groups.google.com/d/msgid/nanopb/22e6d7e8-3cda-4756-bfe1-9b
> a72d134267n%40googlegroups.com.
>
> References
>
> 1. https://jpa.kapsi.fi/nanopb/docs/reference.html#defining-the-options-in-a-.options-file
> 2. https://github.com/nanopb/nanopb/blob/master/examples/network_server/fileproto.options
> 3. file:///tmp/neomutt.html
> 4. https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b...@googlegroups.com
> 5. file:///tmp/neomutt.html
> 6. https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b-8b12-5f6
> 7. http://40googlegroups.com/
> 8. file:///tmp/neomutt.html
> 9. https://groups.google.com/d/msgid/nanopb/1c27fe2d-d259-429b...@googlegroups.com?utm_medium=email&utm_source=footer
> 10. mailto:nanopb+un...@googlegroups.com
> 11. https://groups.google.com/d/msgid/nanopb/22e6d7e8-3cda-4756...@googlegroups.com?utm_medium=email&utm_source=footer


Reply all
Reply to author
Forward
0 new messages