gpt4 book ai didi

go - makefile 中的 protoc 以构建 protobuf

转载 作者:IT王子 更新时间:2023-10-29 01:12:15 28 4
gpt4 key购买 nike

我已经像 https://github.com/google/protobuf/blob/master/src/README.md 上的教程一样安装了 Protocol Buffer

之后我想构建 protobuf 并使用如下命令安装 go 库:

go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
make # generate app and protobuf

我的根目录下有文件 Makefile :

get:
echo "Build Proto"
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --go_out=plugins=grpc:.
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --grpc-gateway_out=logtostderr=true:.
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --swagger_out=logtostderr=true:.
echo "Build APP"
CGO_ENABLED=0 GOOS=linux go build -o ./server/storeitemservice ./server/cmd/server/main.go

但我想使用命令 make 在我的应用程序根目录中生成应用程序和 protobuf 来构建我的应用程序,结果如下:

echo "Build Proto"
Build Proto
protoc -I/usr/local/include -I. -IOPATH/src -IOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --go_out=plugins=grpc:.
OPATH/src: warning: directory does not exist.
OPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis: warning: directory does not exist.
google/api/annotations.proto: File not found.
proto/item.proto: Import "google/api/annotations.proto" was not found or had errors.
Makefile:2: recipe for target 'get' failed
make: *** [get] Error 1

在看到这样的问题后,我检查了它的每个目录,结果是所有。

最佳答案

你需要像这样包装你的 $GOPATH

protoc -I/usr/local/include -I. -I$(GOPATH)/src \
-I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
proto/item.proto --go_out=plugins=grpc:.
添加了

\ 以使其更易于阅读。关键是 $(GOPATH)$GOPATH

这是一个演示:

get:
echo $(GOPATH)
echo $GOPATH

和输出

echo /Users/sberry/Development/golang
/Users/sberry/Development/golang
echo OPATH
OPATH

在了解 Makefile 语法的编辑器中,您可以看到差异

vim view

关于go - makefile 中的 protoc 以构建 protobuf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49085355/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com