登录
首页 >  Golang >  Go问答

macOS (10.14.6) 上使用 `shirou/gopsutil` Go 包时遇到供应商包失败问题

来源:stackoverflow

时间:2024-02-18 12:00:27 481浏览 收藏

一分耕耘,一分收获!既然都打开这篇《macOS (10.14.6) 上使用 `shirou/gopsutil` Go 包时遇到供应商包失败问题》,就坚持看下去,学下去吧!本文主要会给大家讲到等等知识点,如果大家对本文有好的建议或者看到有不足之处,非常欢迎大家积极提出!在后续文章我会继续更新Golang相关的内容,希望对大家都有所帮助!

问题内容

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

# 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

解决方案


事实证明,此错误是由一个众所周知的问题引起的,即 go modvendor 修剪非包目录,从而导致 shirou/gopsutilhost/include 文件夹(其中包含 smc.c 文件)被修剪:

https://github.com/golang/go/issues/26366

已报告此问题对 shirou/gopsutil 的影响:

https://github.com/shirou/gopsutil/issues/832

显然没有简单的解决方案,但目前的解决方法是手动将丢失的目录复制到 vendor/github.com/shirou/gopsutil。就我而言,我将 freebsd_headersinclude$GOPATH/pkg/mod/github.com/shirou/gopsutil/host 复制到 $GOPATH/src/github.com/influxdata/telegraf/vendor/github.com/shirou/ gopsutil 并成功了。

希望您觉得这有帮助。

到这里,我们也就讲完了《macOS (10.14.6) 上使用 `shirou/gopsutil` Go 包时遇到供应商包失败问题》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>