Loading

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

事情是这样的:我参考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

posted @ 2019-09-11 11:48  ZJH_BLOGS  阅读(5988)  评论(0编辑  收藏  举报