shirou / gopsutil

psutil for golang
Other
10.57k stars 1.58k forks source link

macOS: Unable to build using Go Modules #832

Closed paulquerna-okta closed 4 years ago

paulquerna-okta commented 4 years ago

Describe the bug

To Reproduce Go mod vendor gopsutil, then try to build:

# 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"
          ^~~~~~~~~~~~~~~
1 error generated.

Environment (please complete the following information):

jetgeng commented 4 years ago

i meet the same issue. sw_vers out is:

ProductName:    Mac OS X
ProductVersion: 10.15.3
BuildVersion:   19D76

uname -a is:

Darwin Gengs-MBP.geng 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan  9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
axetroy commented 4 years ago

Is there any solution for this now?

mafredri commented 4 years ago

@axetroy no good solution. But as a work-around you can manually copy the missing source/header files to your vendor folder (in the appropriate directory) and commit them. Note that go mod will get rid of them the next time it's run, so care must be taken.

The solution is to either add dummy .go files to the directories so that they will be considered as Go modules or to move them up a directory so they are accompanied by Go files.

axetroy commented 4 years ago

@mafredri Thx. if this is a solution. why not send a PR and create an empty go file in the folder.

This issue should have stumped too many people

Lomanic commented 4 years ago

Weeks or months ago I tried to rename include/smc.{c,h} to host_darwin.{c,h}, as in the disk package, didn't commit this work anywhere unfortunately as this was not compiling anymore or (as I better remember it) had build warnings that I didn't understand how to remove.

Will try the empty .go file workaround, to satisfy this (once again) broken go-mod.