在 macOS (10.14.6) 上使用“shirou/gopsutil”Go 包作为供应商包失败

我试图在influx/telegraf本地构建并使用go mod vendor命令供应所有包。然而,有趣的是,构建失败后出现以下错误:


# github.com/shirou/gopsutil/host

vendor/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/telegraf

go get -d github.com/influxdata/telegraf


# CD into the project

cd $GOPATH/src/influxdata/telegraf


# Checkout v1.14.5 (the current latest version)

git checkout v1.14.5


# Fetch the modules under vendor/ directory

go 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 above

make


天涯尽头无女友
浏览 153回答 2
2回答

慕桂英4014372

事实证明,这个错误是由一个众所周知的问题引起的,即go mod vendor修剪非包目录,从而导致包含文件的host/include文件夹被修剪:shirou/gopsutilsmc.chttps://github.com/golang/go/issues/26366shirou/gopsutil已经报告了此问题的影响:https://github.com/shirou/gopsutil/issues/832显然没有简单的解决方案,但目前的解决方法是将丢失的目录手动复制到vendor/github.com/shirou/gopsutil. 在我的情况下,我复制freebsd_headers并include从$GOPATH/pkg/mod/github.com/shirou/gopsutil/hostto$GOPATH/src/github.com/influxdata/telegraf/vendor/github.com/shirou/gopsutil并且它有效。我希望你觉得这有帮助。

白板的微信

您可以进行手动复制。我发现下面的解决方法也很有帮助。运行这些命令go get github.com/shirou/gopsutil go mod vendor
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go