du90093662774150 2018-03-03 14:46
浏览 794

在makefile中建立protobuf的protoc

I have installed a protocol buffer like the tutorial on https://github.com/google/protobuf/blob/master/src/README.md

after that I want to build protobuf and install go library with command as follows:

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

I have file Makefile on my root like this :

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

but I want to generate app and protobuf in my root of application with the command make to build my app and the result like this:

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

after seeing the problem like this I check each of its directory, and it turns out there is all.

  • 写回答

1条回答 默认 最新

  • drpfu51608120170 2018-03-03 16:20
    关注

    You'll need to wrap your $GOPATH like this

    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:.
    

    \ added to make it easier to read here. The key is $(GOPATH) vs $GOPATH

    Here is a demo:

    get:
        echo $(GOPATH)
        echo $GOPATH
    

    and the output

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

    In an editor that knows Makefile syntax you can see the difference

    vim view

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。