mac编译linux可运行程序
1. 查看GOROOT
go env
GOROOT="/usr/local/Cellar/go/1.10.1/libexec"
2. 创建目标平台所需的包和工具文件
cd /usr/local/Cellar/go/1.10.1/libexec/src
sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash
错误如下:
Building Go cmd/dist using /Users/xxx/go1.4.
ERROR: Cannot find /Users/xxx/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
3. 编译go1.4
git clone https://github.com/golang/go.git
cd go
git branch
git checkout release-branch.go1.4
git branch
cd src/
./all.bash
4. 拷贝go1.4
cp -R /Users/xxx/GitHub/go /Users/xxx/go1.4
5. 重新执行-步骤1
cd /usr/local/Cellar/go/1.10.1/libexec/src
sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash
结果如下:
Installed Go for linux/amd64 in /usr/local/Cellar/go/1.10.1/libexec
Installed commands in /usr/local/Cellar/go/1.10.1/libexec/bin
6. 编译工程
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o control-amd64