4

i wrote an .options file and placed it in the same directory as the .proto file. then, I tried to compile it (using nanopb compiler) by using the command

generator-bin/protoc --nanopb_out=. message.proto -s message.options

and got this error:

Unknown flag: -s

so what am I doing wrong? do I need to import my options file in the .proto file? is there anything else I should do to make it work?

me and stuff
  • 195
  • 1
  • 5
  • 12

1 Answers1

3

Google's protoc has a special syntax for passing options to the plugins. The plugin options are put as argument to nanopb_out and separated from the actual destination path by colon (:).

generator-bin/protoc '--nanopb_out=-v -f message.options:.' message.proto

However, if your .options file has the same name as the .proto and is in the same directory, nanopb plugin should automatically find and use it.

Also note that the -s flag to nanopb expects a pair of settings on the command line, while -f takes a filename. Specifying -v is also useful to get detailed messages whether it loaded the options file or not. You can get full list of command line options by running:

generator-bin/nanopb_generator --help
jpa
  • 10,351
  • 1
  • 28
  • 45
  • For me this does not work. It seams, that the plugin only accepts one parameter. If I try `generator-bin/protoc --nanopb_out=-T -v:. message.proto` I get an error `Unknown flag: -v`. Also your trick with single quotes did not help. – ChristianMurschall Jun 07 '18 at 12:35
  • 1
    The plugin itself does accept multiple parameters, but it can be difficult to get them passed through `protoc`. Quoting the whole part should work when used at the shell. If nothing helps, you can always do it in two steps: `protoc -o message.pb message.proto` and `python nanopb_generator.py -T -v message.pb`. – jpa Jun 07 '18 at 12:38
  • Thanks! That helped! – ChristianMurschall Jun 07 '18 at 14:10