查看: 35|回覆: 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.

在本版发帖返回顶部