go交叉编译参数
在main.go所在的目录下
linux、freebsd和Mac下编译windows可执行程序:
GOOS=windows GOARCH=amd64 go build -o test.exe
windows下编译linux可执行程序:
SET GOOS=linux
SET GOARCH=amd64
go build -o test
参数解析:
- GOOS:目标操作系统
- GOARCH:目标操作系统的架构
| OS | ARCH | OS version |
|---|---|---|
| linux | 386 / amd64 / arm | >= Linux 2.6 |
| darwin | 386 / amd64 | OS X (Snow Leopard + Lion) |
| freebsd | 386 / amd64 | >= FreeBSD 7 |
| windows | 386 / amd64 | >= Windows 2000 |