gpt4 book ai didi

go - 使用 vendor 目录中的本地依赖项时发生编译错误

转载 作者:行者123 更新时间:2023-12-01 22:36:42 24 4
gpt4 key购买 nike

构建(失败):

GO111MODULE=off go build -o diameter

[pceuser@pincb-brm02 src]$ echo $GOPATH 

/ home / pceuser / policy-control-engine

[pceuser@pincb-brm02 src]$ pwd

/ home / pceuser / policy-control-engine / src

[pceuser@pincb-brm02 src]$ ls

backupgx config.go data.csv go.mod gx.go model.go自述文件redis_test.go stats.go ccr.go config.yml直径go.sum Makefile pcediam redis.go server.go供应商

[pceuser@pincb-brm02 src]$ cd vendor
[pceuser@pincb-brm02 vendor]$ ls

github.com golang.org gopkg.in modules.txt

生成错误:
ccr.go:8:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam" in any of:
/usr/local/go/src/github.com/fiorix/go-diameter/v4/diam (from
$GOROOT)
/home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam
(from $GOPATH)

ccr.go:9:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam/avp" in any of:
/usr/local/go/src/github.com/fiorix/go-diameter/v4/diam/avp (from
$GOROOT)
/home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam/avp
(from $GOPATH)

gx.go:11:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam/datatype" in any of:
/usr/local/go/src/github.com/fiorix/go-diameter/v4/diam/datatype
(from $GOROOT)
/home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam/datatype
(from $GOPATH)

ccr.go:6:2: cannot find package
"github.com/fiorix/go-diameter/v4/diam/sm" in any of:
/usr/local/go/src/github.com/fiorix/go-diameter/v4/diam/sm (from
$GOROOT)
/home/pceuser/policy-control-engine/src/github.com/fiorix/go-diameter/v4/diam/sm
(from $GOPATH)

redis.go:6:2: cannot find package "github.com/go-redis/redis" in any
of: /usr/local/go/src/github.com/go-redis/redis (from $GOROOT)
/home/pceuser/policy-control-engine/src/github.com/go-redis/redis
(from $GOPATH)

config.go:6:9: cannot find package "gopkg.in/yaml.v2" in any of:
/usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
/home/pceuser/policy-control-engine/src/gopkg.in/yaml.v2 (from
$GOPATH)

注意:我在自己的 https://github.com/fiorix/go-diameter中做了一些更改
供应商依赖文件夹,但仍然无法编译。

最佳答案

如果您不在GOPATH范围内并且不使用go modules而仍然尝试通过使用vendor文件夹来编译项目,则值得尝试:

go build -mod=vendor

这样可以防止在全局 GOPATH中找到依赖项,并将直接从 vendor文件夹中加载依赖项。

关于go - 使用 vendor 目录中的本地依赖项时发生编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61025410/

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