'Unknown flag: --go_opt while regenerating gRPC code

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


Solution 1:[1]

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"

Solution 2:[2]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BMW
Solution 2 Abhinav Mathur