BlockchainGeek
BlockchainGeek

Reputation: 321

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

Upvotes: 9

Views: 18089

Answers (4)

Jay Ehsaniara
Jay Ehsaniara

Reputation: 1529

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

protoc --proto_path=helloworld --go_out=paths=source_relative:. -I. helloworld/*.proto

Upvotes: 0

Abhinav Mathur
Abhinav Mathur

Reputation: 8101

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)

Upvotes: 3

user13951318
user13951318

Reputation: 91

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"

Upvotes: 9

Michael Wang
Michael Wang

Reputation: 438

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

Upvotes: -4

Related Questions