在macOS(10.14.6)上将`shirou/gopsutil` Go软件包用作供应商的软件包失败 [英] Using `shirou/gopsutil` Go package as a vendored package fails on macOS (10.14.6)

查看:85
本文介绍了在macOS(10.14.6)上将`shirou/gopsutil` Go软件包用作供应商的软件包失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在本地构建 influx/telegraf 并使用 go mod vendor 命令提供所有软件包.但是,有趣的是,此后构建失败,并显示以下错误:

 #github.com/shirou/gopsutil/hostvendor/github.com/shirou/gopsutil/host/host_darwin_cgo.go:9:11:致命错误:找不到"include/smc.c"文件#include"include/smc.c"^ ~~~~~~~~~~~~~~ 

重现步骤(设置GOPATH变量后):

 #提取项目,例如涌入/远距离移植去获取-d github.com/influxdata/telegraf#将CD放入项目cd $ GOPATH/src/influxdata/telegraf#Checkout v1.14.5(当前最新版本)git checkout v1.14.5#获取vendor/目录下的模块去mod供应商#然后修改Makefile,如下所示:#1.移除`deps`目标及其在`all`目标中的引用;由于我们已获取所有模块,因此不再需要它.#2.在调用"go build","go install"或"go test"的所有位置添加"-mod vendor"标志.这是必要的,因为Telegraf v1.14.5仍处于Go的1.12版本中,这要求该标志使用`vendor/`目录下的模块.#最后,构建项目,您应该得到上面的错误制作 

解决方案

原来,此错误是由一个众所周知的问题引起的,该问题导致 go mod vendor 修剪非软件包目录,从而导致包含 smc.c 文件的 shirou/gopsutil host/include 文件夹:

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 复制到了 $ GOPATH/src/github.com/influxdata/telegraf/vendor/github.com/shirou/gopsutil 即可.

希望您对此有帮助.

I was trying to build influx/telegraf locally and vendor all the packages using go mod vendor command. However, interestingly, the build fails after that with the following error:

# 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"
          ^~~~~~~~~~~~~~~

Steps to reproduce (after setting GOPATH variable):

# 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

解决方案

It turned out that this error is caused by a well known issue whereby go mod vendor prunes non-package directories, hence causing the host/include folder of shirou/gopsutil, which contains the smc.c file, to be pruned:

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

The impact of this issue on shirou/gopsutil is already reported:

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

There is no easy solution apparently, but a work-around for now is to manually copy the missing directories to vendor/github.com/shirou/gopsutil. In my case, I copied freebsd_headers and include from $GOPATH/pkg/mod/github.com/shirou/gopsutil/host to $GOPATH/src/github.com/influxdata/telegraf/vendor/github.com/shirou/gopsutil and it worked.

I hope you find this helpful.

这篇关于在macOS(10.14.6)上将`shirou/gopsutil` Go软件包用作供应商的软件包失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆