Unable to build protobuf to go endpoint

后端 未结 12 783
日久生厌
日久生厌 2021-01-30 12:39

using protobuf version 2.6.1 ( which i installed via homebrew)

I am trying to run

$ protoc --go_out=../cloud/ *.proto

I keep receiv

相关标签:
12条回答
  • 2021-01-30 12:59

    I met the same problem.

    $ protoc --go_out=plugins=grpc:pb/ *.proto
    protoc-gen-go: program not found or is not executable
    --go_out: protoc-gen-go: Plugin failed with status code 1.
    

    The solution as below:

    Find the installation directory of protoc-gen-go, it must be in your $PATH.

    export PATH=$PATH:/path/to/dir
    

    You'd better add it to your .bash_profile

    echo $"export PATH=\$PATH:$(/path/to/dir)" >> ~/.bash_profile
    source ~/.bash_profile
    

    then everything is ok.

    0 讨论(0)
  • 2021-01-30 12:59

    I have Ubuntu 18.04.02 LTS and installed protoc using

    sudo apt install protobuf-compiler
    

    I have my GOPATH and GOBIN set correctly, but still when I did a protoc --go_out=. <filename> I was getting

    protoc-gen-go: program not found or is not executable
    --go_out: protoc-gen-go: Plugin failed with status code 1.
    
    

    After reading bunch of places, was able to find that doing

    go get -u github.com/golang/protobuf/protoc-gen-go
    

    was able to fix the issue. Hope this helps someone out there.

    0 讨论(0)
  • 2021-01-30 13:01

    Mby will help for somebody. I'm on Fedora 29.

    When I installed Go I did:

    echo 'export GOPATH=$HOME/Go' >> $HOME/.bashrc
    source $HOME/.bashrc
    

    So I have my GOPATH set up. Next I do:

    echo 'export PATH=$PATH:$GOPATH/bin' >> $HOME/.bashrc
    source $HOME/.bashrc
    

    And my protoc compiler work lika a charm.

    0 讨论(0)
  • 2021-01-30 13:02
    1. You should properly define your GO_PATH - where your go packages live. In other words, GO_PATH is your go workspace. The GO_PATH should be ~/go.

    2. protoc-gen-go should be in your PATH. While protoc-gen-go lives in $GO_PATH/bin after you installed it.


    Add these 2 important lines to your ~/.bash_profile:

    export GO_PATH=~/go
    export PATH=$PATH:/$GO_PATH/bin
    

    Then you need to start a new shell session or just type in this line:

    $ source ~/.bash_profile
    
    0 讨论(0)
  • 2021-01-30 13:04

    Directly from grpc documentation:

    Go plugins for the protocol compiler:

    Install the protocol compiler plugins for Go using the following commands:

    $ export GO111MODULE=on  # Enable module mode
    $ go get google.golang.org/protobuf/cmd/protoc-gen-go \
             google.golang.org/grpc/cmd/protoc-gen-go-grpc
    

    Update your PATH so that the protoc compiler can find the plugins:

    $ export PATH="$PATH:$(go env GOPATH)/bin"
    
    0 讨论(0)
  • 2021-01-30 13:06

    protoc-gen-go needs to be in your shell path, i.e. one of the directories listed in the PATH environment variable, which is different from the Go path. You can test this by simply typing protoc-gen-go at the command line: If it says "command not found" (or similar) then it's not in your PATH.

    0 讨论(0)
提交回复
热议问题