登录
首页 >  Golang >  Go问答

错误: 缺乏必要的输入或程序无法执行时,如何编译protocol buffer

来源:stackoverflow

时间:2024-03-10 08:27:24 133浏览 收藏

Golang小白一枚,正在不断学习积累知识,现将学习到的知识记录一下,也是将我的所得分享给大家!而今天这篇文章《错误: 缺乏必要的输入或程序无法执行时,如何编译protocol buffer》带大家来了解一下##content_title##,希望对大家的知识积累有所帮助,从而弥补自己的不足,助力实战开发!


问题内容

我正在尝试在 mac 上制作 golang+grpc 服务器。我安装了 golang、grpc、protocol buffer 并按照此示例检查了 grpc 服务器 https://grpc.io/docs/quickstart/go/ 问题是当我尝试使用协议缓冲区编译 .proto 文件时,它说“缺少输入”或“程序不可执行”。

安装protocol buffer和grpc

brew install grpc protobuf

安装基于golang的protoc插件

go get github.com/golang/protobuf/protoc-gen-go

协议路径

which protoc
/usr/local/bin/protoc

示例位置

/users/usrname/go/src/google.golang.org/grpc/examples/helloworld

运行原型编译器

protoc -i=/users/username/go/src/google.golang.org/grpc/examples/helloworld/helloworld/ --go_out=/users/username/go/src/google.golang.org/grpc/examples/helloworld/helloworld/ /users/username/go/src/google.golang.org/grpc/examples/helloworld/helloworld/helloworld.proto

错误信息

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.

解决方案


golang/protobuf issue 795中提到了这一点

参见Installation section of the page README

从存储库中获取代码并安装原型包。
最简单的方法是运行 go get -u github.com/golang/protobuf/protoc-gen-go

除非设置了 $GOBIN,否则编译器插件 protoc-gen-go 将安装在 $GOPATH/bin 中。它必须位于您的 $PATH 中,协议编译器 protoc 才能找到它。

因此请仔细检查您的 $GOPATH 的值(如果未设置,则默认为 ~/go

如果 $GOPATH/bin (或 ~/go/bin)在你的 $PATH 中?

OP camilla 确认不是:

$PATH 也有 :/Users/username/go/bin/protoc-gen-go

它应该有 :/Users/username/go/bin

终于介绍完啦!小伙伴们,这篇关于《错误: 缺乏必要的输入或程序无法执行时,如何编译protocol buffer》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>