go build
By default, go build combines symbol and debug info with binary files. However, you can remove the symbol and debug info with go build -ldflags “-s -w”.
go build 默认参数是 debug 版,加编译参数-ldflags “-w -s”才是 release. -w 为去掉调试信息,-s 为去掉符号表,文件大小会减小。
1 | go build -ldflags "-w -s" |
golang 交叉编译
1 | GOOS=linux GOARCH=amd64 go build hello.go |
参数解析
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 |