无法运行 protoc 命令而不遇到错误。

huangapple go评论78阅读模式
英文:

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

问题

我对使用协议缓冲区(protocol buffers)还比较新手,在使用Go语言时遇到了一些问题。我一直在参考一些帖子和视频教程,以便安装和设置协议缓冲区,并创建我的make文件。我目前尝试过的是:

使用以下命令进行安装:

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

然后执行:

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

我使用tree命令查看了使用unzip命令创建的目录的内容,如下所示:

/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

然后我尝试将命令添加到路径中:

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

这样我就可以运行命令 protoc --version,输出为:libprotoc 3.17.3

然而,在编写proto文件后,我尝试运行以下命令:

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

然后:

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

但是会产生以下错误:

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.

我已经查看了其他帖子,但没有找到适用的解决方案。我使用的是macOS 10.13.6,使用的是zsh而不是bash,我已经尝试了很多方法,但是还是没有解决。如果有人有任何建议,我将非常感激。

英文:

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.

答案1

得分: 2

你需要使用以下命令安装protoc-gen-go

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

使用go get进行安装已经被弃用。

英文:

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.

huangapple
  • 本文由 发表于 2021年10月28日 21:09:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/69754678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定