查看: 18|回复: 0

使用 go protoc --go_out 输出的 *.pb.go文件时报 undefined: proto.ProtoPackageIsVersion3

[复制链接]

2

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-6-18
发表于 2019-9-11 11:48:00 | 显示全部楼层 |阅读模式

事情是这样的:我参考go的 grpc 实现 https://grpc.io/docs/quickstart/go/

Download the example

The grpc code that was fetched with go get google.golang.org/grpc also contains the examples. They can be found under the examples dir: $GOPATH/src/google.golang.org/grpc/examples.

根据教程一步一部执行helloword demo 重新转换修改后的 helloword.proto 文件至 helloword.go.proto 文件后

protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld

再执行 

go run greeter_server/main.go

就报错

helloworld\helloworld.pb.go:25:11: undefined: proto.ProtoPackageIsVersion3

通过 go get -u google.golang.org/grpc 安装的 protoc-gen-go版本永远是最新的(支持v3)

而使用grpc教程 demo 用的包是 protoc-gen-go v1.2.0 版本 (不支持v3 )

 go get -u google.golang.org/grpc

 

如何切换安装 v1.2.0版本?

If you need a particular version of protoc-gen-go (e.g., to match your proto package version), one option is

GIT_TAG="v1.2.0" # change as needed
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go

 

参考:https://stackoverflow.com/questions/53952723/undefined-proto-protopackageisversion3



来源:https://www.cnblogs.com/zjhblogs/p/11505432.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部