0

i'm running osx

$ uname -rsv
Darwin 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64

installed with brew and from binaries both didn't work

$ brew install protobuf
$ protoc --version 
libprotoc 3.19.4

i'm getting an error when i'm trying to generate code using protos and grpc it says --go-out unknown flag

$ protoc -I protos/ protos/curr.proto --go-out=plugins=grpc:protos/curr
Unknown flag: --go-out
make: *** [protos] Error 1

After installing from pre-compiled binaries ( didn't work )

$ PB_REL="https://github.com/protocolbuffers/protobuf/releases"
$ curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
$ unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
$ export PATH="$PATH:$HOME/.local/bin"

-bash: /$HOME/.local/bin/protoc: cannot execute binary file

Any idea how to solve this ?

3 Answers3

0

You need the protoc-gen-go and protoc-gen-grpc plugins as stated on gRPC Go Quickstart

Yuri Golobokov
  • 1,829
  • 12
  • 11
0

even after installing protoc-gen-go and protoc-gen-grpc plugins kept giving an error

protoc --go_out=plugins=grpc:./protos  --go_opt=paths=source_relative protos/currency.proto
--go_out: protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC

somehow this's in mac doesn't work due to no support for plugins

to solve you need to add

option go_package = "."; to your .proto file

then running should solve it .

protoc --go_out=.  --go_opt=paths=source_relative  --go-grpc_out=. --go-grpc_opt=paths=source_relative  ./protos/myproto.proto

0

This error: --go_out: protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC is due to the fact that plugins are not supported in --go_out anymore.

you will need to use the --go-grpc_out flag to generate your gRPC-related code. So you can do something like:

protoc --go_out=./protos --go-grpc_out=./protos  --go_opt=paths=source_relative protos/currency.proto

Also note that adding option go_package = "."; kind of suppress the purpose of packages. what you can do instead is passing the module options, just like:

protoc --go_out=. --go-grpc_out=. --go_opt=module=example.com/m --go-grpc_opt=module=example.com/m protos/currency.proto
Clément Jean
  • 1,735
  • 1
  • 14
  • 32