1. 安装 gcc-mingw-w64

apt-get install gcc-mingw-w64

2. 跨平台编译

生成 64位 exe 可执行文件.

env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -o main.exe main.go

生成 32 位 exe 可执行文件

env CGO_ENABLED=1 GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc go build -o main.exe main.go