我正在尝试使用 cgo 构建一些 go 代码,但在 darwin/arm64 go1.16beta 上构建失败。
我的环境是
GO111MODULE="off"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/a/Library/Caches/go-build"
GOENV="/Users/a/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/a/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/a/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gg/fgcf1wps4tz51d_x38ybzpv00000gn/T/go-build2055022242=/tmp/go-build -gno-record-gcc-switches -fno-common"
去建造
>>>
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/gg/fgcf1wps4tz51d_x38ybzpv00000gn/T/go-link-948954574/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
...
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
去构建 -v -ldflags="-linkmode=internal"
>>>
loadmacho: /Users/haoliu/Library/Caches/go-build/67/6777448f029f7eb3953d5848709f80c5ab0f3bf855d852152a1d23834392afea-d(_x001.o): mach-o object but not arm64
loadmacho: /Users/haoliu/Library/Caches/go-build/67/6777448f029f7eb3953d5848709f80c5ab0f3bf855d852152a1d23834392afea-d(_x002.o): mach-o object but not arm64
我尝试下载 llvm/clang 并从源代码构建,但 clang 目标仍然是x86_64-apple-darwin20.1.0