protoc-gen-go:程序未找到或无法执行,尽管已安装

问题描述 投票:0回答:1

我已经安装了 go 插件。当我尝试运行 events.proto 代码时,它仍然显示错误:

sudo go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
sudo go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

文件结构:

pegasus@pegasus:~/Documents/eBPF/go-xdp-examples/gRPC_test$ tree
.
└── events.proto

1 directory, 1 file
pegasus@pegasus:~/Documents/eBPF/go-xdp-examples/gRPC_test$ 

生成go代码使用的命令:

pegasus@pegasus:~/Documents/eBPF/go-xdp-examples/gRPC_test$ sudo protoc --go_out=. --proto_path=/home/pegasus/Documents/eBPF/go-xdp-examples/gRPC_test --go_opt=paths=source_relative   --go-grpc_out=. --go-grpc_opt=paths=source_relative /home/pegasus/Documents/eBPF/go-xdp-examples/gRPC_test/events.proto
protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.

在我的

~/.bashrc

里面
export PATH=$PATH:$(go env GOPATH)/bin

export PATH=$PATH:$HOME/go/bin
export PATH=$PATH:/usr/local/go/bin

进入二进制路径:

pegasus@pegasus:~$ which go
/usr/local/bin/go
pegasus@pegasus:~$ whereis go
go: /usr/bin/go /usr/lib/go /usr/local/bin/go /usr/local/go /usr/share/go /home/pegasus/go/bin/go /usr/share/man/man1/go.1.gz

GOPATH

pegasus@pegasus:~$ go env GOPATH
/home/pegasus/go

去环境输出:

pegasus@pegasus:~$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/pegasus/.cache/go-build"
GOENV="/home/pegasus/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/pegasus/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pegasus/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.20/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build917789205=/tmp/go-build -gno-record-gcc-switches"

我该如何修复它?我想解决

sudo go install
问题和 protoc-gen-go 问题。我应该在哪里设置我的GOBIN? 由于我是新手,也许我问了一些天真的问题。

go protocol-buffers protobuf-go
1个回答
0
投票

这是关于如何下载/使用 gRPC 的 go protoc 插件的一个很好的演练:https://grpc.io/docs/languages/go/quickstart/

© www.soinside.com 2019 - 2024. All rights reserved.