在macOS下启用CGO_ENABLED的交叉编译

在启用CGO_ENABLED的情况下,尝试使用下面命令进行Windows平台的交叉编译:

$ CGO_ENABLED= GOOS=windows GOARCH= go build -x -v -ldflags "-s -w"

出现错误如下:

# runtime/cgo
gcc_libinit_windows.c::: fatal error: 'windows.h' file not found

安装mingw-w64

# piao @ PiaodeMacBook-Pro in ~ [::]
$ brew install mingw-w64
==> Downloading https://homebrew.bintray.com/bottles/mingw-w64-5.0.4_1.mojave.bottle.tar.gz
Already downloaded: /Users/piao/Library/Caches/Homebrew/downloads/954c462f9298678f85a2ca518229e941d1daed366c84c339900c756e7ca8ad25--mingw-w64-5.0.4_1.mojave.bottle.tar.gz
==> Pouring mingw-w64-5.0.4_1.mojave.bottle.tar.gz
05-11 15:49