Unknown flag: --go_opt while regenerating gRPC code
Asked Answered
E

4

8

I followed the gRPC quickstart document in this link https://grpc.io/docs/languages/go/quickstart/ and while regenerating the gRPC code i am getting error ( Unknown flag: --go_opt) as shown below. Tried all the options but not working. It also gives ( Unknown flag: --go-grpc_opt) error.

Command -

$ protoc \
  --go_out=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config:. \
  --go-grpc_out=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config:. \
  --go-grpc_opt=paths=source_relative \
  helloworld/helloworld.proto

Error - Unknown flag: --go_opt
Esmeraldaesmerelda answered 15/7, 2020 at 6:46 Comment(8)
Instead of a screenshot, can you copy paste the command you run? It looks like you hit this issue: github.com/grpc/grpc.io/issues/298#issuecomment-656767393 You need to install protoc-gen-go-grpc in your PATHLambart
Do not paste images of textHeteroclite
I have already tried github.com/grpc/grpc.io/issues/298#issuecomment-656767393 as it is given in the mentioned link here grpc.io/docs/languages/go/quickstart. This is the command ( cd ../../cmd/protoc-gen-go-grpc && go install . )Esmeraldaesmerelda
can you verify if protoc-gen-go or protoc-gen-go-grpc binary is present in your PATH?Lambart
I can see protoc-gen-go-grpc folder under grpc-go/cmdEsmeraldaesmerelda
it doesn't imply it is in the path. 3. prerequisite in the tutorial has this command: $ export PATH="$PATH:$(go env GOPATH)/bin" which adds GOPATH/bin to your PATH. When you do go install binary will be in your PATH. You can. verify if binary is on your path by using which command. ie: which protoc-gen-goLambart
I used command (which protoc-gen-go) and went to the path listed by the command. I can see protoc-gen-go there.Esmeraldaesmerelda
I also installed protoc-gen-go-grpc but again same error.Esmeraldaesmerelda
R
9

I had a same issue. I removed the installed protobuf compiler and reinstalled protobuf compiler with "Install pre-compiled binaries" option in https://grpc.io/docs/protoc-installation/.

sudo apt-get remove protobuf-compiler
$PB_REL="https://github.com/protocolbuffers/protobuf/releases"
$ curl -LO $PB_REL/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip

$sudo apt install unzip
$unzip protoc-3.12.1-linux-x86_64.zip -d HOME/.local

$export PATH="$PATH:$HOME/.local/bin"
Rosenthal answered 18/7, 2020 at 2:10 Comment(1)
The _opt flavor is only supported on newer versions of the compiler. If you don't want to install a newer version than your package manager provides, you can also simply move the paths=source_relative into the --go_out= section like --go_out=paths=source_relative:Mpath/to/file.proto=desired/go/package:<outdir>.Acinaciform
E
3

The issue seems common with a few different pain points, so I'll add a answer that might be useful for a highlighting a bunch of problems:

  1. Older versions of the compiler don't have the _opt flag
  2. protoc has a --foo_opt flag only if you also specify a --foo_out flag
  3. A few tutorials might be using incorrect export commands, so verify that the protoc and other binaries such protoc-gen-go-grpc are actually added to the path (there are many ways to check/modify the PATH variable depending on the system, adding basic resources to get started on Windows or Unix)
Evanevander answered 22/4, 2022 at 5:15 Comment(1)
1. did it for me: protoc --version >= 3.12 solved the _opt errorFestal
N
0

I was getting the same error, then I tried like this:

protoc --proto_path=helloworld --go_out=paths=source_relative:. -I. helloworld/*.proto
Nickens answered 29/12, 2023 at 19:45 Comment(0)
W
-4

You are missing the 4th line: --go_opt=paths=source_relative \.

Woodyard answered 9/9, 2020 at 13:55 Comment(2)
Yes but this is not the problem. You should add this as a comment to the initial question.Acinaciform
@Acinaciform This IS the problem. Adding the missing line and the compilation is passed.Woodyard

© 2022 - 2024 — McMap. All rights reserved.