Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc:add gopsutil problem solution #13

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions _posts/2024-11-12-test-markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
layout: post
title: 'gopsutil undefined: KinfoProc'
subtitle:
tags: [Go]
comments: true
---



### 详细报错

```shell
# github.com/shirou/gopsutil/process
../../../go/pkg/mod/github.com/shirou/[email protected]+incompatible/process/process_darwin.go:395:7: undefined: KinfoProc
../../../go/pkg/mod/github.com/shirou/[email protected]+incompatible/process/process_darwin.go:423:34: undefined: KinfoProc
../../../go/pkg/mod/github.com/shirou/[email protected]+incompatible/process/process_darwin.go:424:8: undefined: KinfoProc
../../../go/pkg/mod/github.com/shirou/[email protected]+incompatible/process/process_darwin.go:437:32: undefined: KinfoProc
../../../go/pkg/mod/github.com/shirou/[email protected]+incompatible/process/process_darwin.go:439:11: undefined: KinfoProc
make: *** [gaea] Error 1
```

### 解决办法


#### 办法1

> 相关Issue:https://github.com/shirou/gopsutil/issues/149
> If you copy process_darwin_amd64.go to process_darwin_386.go, you can build. But it might be not work because struct size is different.
gongna-au marked this conversation as resolved.
Show resolved Hide resolved
> Since I can not get i386/darwin machine, I can not get struct size on 386 environment. FreeBSD/Linux on i386 can be get from AWS, but no darwin.
> I can just add process_darwin_386.go to the repository, with warning comment. Do you really needs to darwin/386?



简言之:修改gopsutil包中 `process_darwin_amd64.go`文件名为`process_darwin.go`
gongna-au marked this conversation as resolved.
Show resolved Hide resolved

#### 办法2

如果make时出现关于这个包的错误https://github.com/shirou/gopsutil,在go.mod 和go.sum 下删除gopsutil包后重新go mod tidy 后就可以解决了

```shell
- github.com/shirou/gopsutil v2.16.13-0.20170208025555-b62e301a8b99+incompatible
+ github.com/shirou/gopsutil v3.21.11+incompatible
```


### 其他类似的问题


报错...

```shell
go test -coverprofile=.coverage.out `go list ./...` -short
# github.com/shirou/gopsutil/cpu
../../go/pkg/mod/github.com/shirou/[email protected]+incompatible/cpu/cpu_darwin_cgo.go:13:5: error: 'TARGET_OS_MAC' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
13 | #if TARGET_OS_MAC
| ^
1 error generated.

```

详细的报错具体大概是这种,如果想了解错误的原因可以查看官方Issue或者文档github.com/shirou/gopsutil包版本太低导致的TARGET_OS_MAC错误
https://github.com/shirou/gopsutil/issues/976
https://github.com/shirou/gopsutil/pull/1042
gongna-au marked this conversation as resolved.
Show resolved Hide resolved