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

build from source failed on macOS #241

Closed
leleliu008 opened this issue Oct 30, 2022 · 1 comment
Closed

build from source failed on macOS #241

leleliu008 opened this issue Oct 30, 2022 · 1 comment

Comments

@leleliu008
Copy link

reported error messages

# github.com/anatol/smart.go
/Users/runner/go/pkg/mod/github.com/anatol/smart.go@v0.0.0-20220917195147-c0b00d90f8cc/nvme.go:1209:10: undefined: NVMeDevice
/Users/runner/go/pkg/mod/github.com/anatol/smart.go@v0.0.0-20220917195147-c0b00d90f8cc/nvme.go:1213:10: undefined: NVMeDevice
/Users/runner/go/pkg/mod/github.com/anatol/smart.go@v0.0.0-20220917195147-c0b00d90f8cc/nvme.go:1228:10: undefined: NVMeDevice
/Users/runner/go/pkg/mod/github.com/anatol/smart.go@v0.0.0-20220917195147-c0b00d90f8cc/smart.go:34:12: undefined: OpenNVMe

source version
https://github.com/xxxserxxx/gotop/archive/v4.2.0.tar.gz

host environment

macos-11.7 x86_64

go env

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/runner/Library/Caches/go-build"
GOENV="/Users/runner/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/runner/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/runner/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org/,direct"
GOROOT="/usr/local/Cellar/go/1.19.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.19.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="/Applications/Xcode_13.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar"
CC="/opt/ppkg/core/bin/proxy-cc"
CXX="/opt/ppkg/core/bin/proxy-c++"
CGO_ENABLED="0"
GOMOD="/opt/ppkg/installing/gotop/src/go.mod"
GOWORK=""
CGO_CFLAGS="-isysroot /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Qunused-arguments -fPIC -fno-common -Os -Wno-error=unused-command-line-argument"
CGO_CPPFLAGS="-I/opt/ppkg/installing/gotop/inc -isysroot /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Qunused-arguments -DNDEBUG"
CGO_CXXFLAGS="-isysroot /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Qunused-arguments -fPIC -fno-common -Os -Wno-error=unused-command-line-argument"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/opt/ppkg/installing/gotop/lib -isysroot /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Wl,-search_paths_first -Wl,-S"
PKG_CONFIG="/usr/local/bin/pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map

build instruction

go build -trimpath -v -ldflags '-X main.Version=v4.2.0 -X main.BuildDate=20221030T141516 -s -w' -o ./out/ ./cmd/gotop
@leleliu008
Copy link
Author

leleliu008 commented Nov 4, 2022

cgo must be enabled when building on macOS.

following config will do the trick:

export CGO_ENABLED=1

this infomation is very important, but it is not motioned in README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant