我试图在influx/telegraf本地构建并使用go mod vendor命令供应所有包。然而,有趣的是,构建失败后出现以下错误:# github.com/shirou/gopsutil/hostvendor/github.com/shirou/gopsutil/host/host_darwin_cgo.go:9:11: fatal error: 'include/smc.c' file not found #include "include/smc.c" ^~~~~~~~~~~~~~~重现步骤(设置 GOPATH 变量后):# Fetch the project, e.g. influx/telegrafgo get -d github.com/influxdata/telegraf# CD into the projectcd $GOPATH/src/influxdata/telegraf# Checkout v1.14.5 (the current latest version)git checkout v1.14.5# Fetch the modules under vendor/ directorygo mod vendor# Then modify the Makefile as follows:# 1. Remove the `deps` target and its reference in the `all` target; it is not needed anymore, as we fetched all modules.# 2. Add the `-mod vendor` flag everywhere `go build`, `go install`, or `go test` is called. This is necessary since Telegraf v1.14.5 is still on version 1.12 of Go, which requires this flag to use the modules under `vendor/` directory.# Finally, build the project and you should get the error abovemake
2 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
事实证明,这个错误是由一个众所周知的问题引起的,即go mod vendor
修剪非包目录,从而导致包含文件的host/include
文件夹被修剪:shirou/gopsutil
smc.c
https://github.com/golang/go/issues/26366
shirou/gopsutil
已经报告了此问题的影响:
https://github.com/shirou/gopsutil/issues/832
显然没有简单的解决方案,但目前的解决方法是将丢失的目录手动复制到vendor/github.com/shirou/gopsutil
. 在我的情况下,我复制freebsd_headers
并include
从$GOPATH/pkg/mod/github.com/shirou/gopsutil/host
to$GOPATH/src/github.com/influxdata/telegraf/vendor/github.com/shirou/gopsutil
并且它有效。
我希望你觉得这有帮助。
白板的微信
TA贡献1883条经验 获得超3个赞
您可以进行手动复制。我发现下面的解决方法也很有帮助。
运行这些命令
go get github.com/shirou/gopsutil go mod vendor
- 2 回答
- 0 关注
- 151 浏览
添加回答
举报
0/150
提交
取消