http://spf13.com/post/cross-compiling-go/
https://coderwall.com/p/pnfwxg/cross-compiling-golang
安装设置
参考:http://stackoverflow.com/questions/12168873/cross-compile-go-on-osx
可以进入go src目录,然后执行命令(以目标系统是32bit windows为例):
cd /usr/local/go/src
sudo GOOS=windows GOARCH=386 CGO_ENABLED=0 ./make.bash --no-clean
如果是mac,使用homebrew安装的话,可以直接:
$ brew install go --with-cc-common # Linux, Darwin, and Windows
$ brew install go --with-cc-all # All the cross-compilers
如果已经安装过go,可以换成reinstall
命令来重新安装。
编译
设置环境变量:
GOARCH - the architecture, e.g. amd64, 386 or arm
GOOS - the operating system - linux, darwin or windows
示例:
$ GOARCH=arm GOOS=linux go build helloworld
有疑问加站长微信联系(非本文作者)