安装protobuf
在前提条件中,需要安装libtool
sudo yum install libtool
然后安装过程中需要c++11,需要升级gcc的版本到4.7以上
以下目录下已预集成不同gcc的版本
cd /opt/compiler/
export PATH=/opt/compiler/gcc-8.2/bin:$PATH
export LIBRARY_PATH=/opt/compiler/gcc-8.2/lib64/:$LIBRARY_PATH
然后遇到问题:
protoc-gen-go: program not found or is not executable
--go_out: protoc-gen-go: Plugin failed with status code 1.
gen.go:10: running "protoc": exit status 1
解决方案:
https://blog.csdn.net/qq_38639426/article/details/107669849
然后编译proto的文件:
package pack
// To run these commands, make sure that protoc-gen-go and protoc-gen-go-grpc are installed
// > go install google.golang.org/protobuf/cmd/protoc-gen-go
// > go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
//
// Generated files were last generated with:
// - protoc-gen-go: v1.27.1
// - protoc-gen-go-grpc: v1.1.0
//go:generate protoc --go_out=proto所在目录/ --go-grpc_out=proto所在目录/ proto所在目录/proto_test.proto
编译方式:
go generate ./...
后续
grpc对应的pb生成方式
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
对应生成的命令:
protoc xxx.proto --go_out=. //对应pb.go
protoc xxx.proto --go-grpc_out=. //对应xxx_grpc.pb.go
brpc对应的pb生成方式
go install xxxx/brpc/protoc-gen-brpc
对应生成的命令:
protoc xxx.proto --brpc_out=.
网友评论