我已经安装了一个类似于https://github.com/google/protobuf/blob/master/src/README.md上的教程的协议缓冲区
之后,我想用下面的命令构建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在我的应用程序根目录中生成app和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在看到这样的问题后,我检查了它的每个目录,结果是所有目录都在那里。
发布于 2018-03-04 00:20:09
你需要这样包装你的$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语法的编辑器中,您可以看到不同之处

https://stackoverflow.com/questions/49085355
复制相似问题