Home > Blockchain >  Can't seem to run protoc command without running into error
Can't seem to run protoc command without running into error

Time:10-30

I am fairly new to using protocol buffers and am having some trouble with getting them to work with Go. I have been following along with some posts and video tutorials on getting it installed and set up to create my make file. What I have tried so far is:

Installing by using this command:

wget https://github.com/protocolbuffers/protobuf/\ releases/download/v3.9.0/protoc-3.9.0-osx-x86_64.zip

Followed by:

unzip protoc-3.9.0-osx-x86_64.zip -d /usr/local/protobuf

I used the tree command to view the contents of the directory created using the unzip command which looks like:

/usr/local/protobuf
├── bin
│ └── protoc
├── include
│ └── google
│ └── protobuf
│ ├── any.proto
│ ├── api.proto
│ ├── compiler
│ │ └── plugin.proto
│ ├── descriptor.proto
│ ├── duration.proto
│ ├── empty.proto
│ ├── field_mask.proto
│ ├── source_context.proto
│ ├── struct.proto
│ ├── timestamp.proto
│ ├── type.proto
│ └── wrappers.proto └── readme.txt

I then tried to add the command to path

echo 'export PATH="$PATH:/usr/local/protobuf/bin"' >> ~/.zshenv

Which allowed me to run the command protoc --version which gave me the output: libprotoc 3.17.3

However after writing my proto file I tried to run the command

go get google.golang.org/protobuf/...@v1.25.0

And then:

protoc api/v1/*.proto --go_out=. --go_opt=paths=source_relative --proto_path=.

That produces the error:

protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.

I have found the other posts on this and none of the recommended paths have helped. I am running macOS 10.13.6 with zsh not bash and am running out of things to try. If anyone has any suggestions I would be extremely grateful.

CodePudding user response:

You have to install protoc-gen-go with:

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

Installing with go get is deprecated.

  • Related