go 跨平台交叉编译

跨平台交叉编译

# 编译到 linux 64bit
$ GOOS=linux GOARCH=amd64 go build
# 或者可以使用 -o 选项指定生成二进制文件名字
$ GOOS=linux GOARCH=amd64 go build -o app.linux

# 编译到 linux 32bit
$ GOOS=linux GOARCH=386 go build

# 编译到 windows 64bit
$ GOOS=windows GOARCH=amd64 go build

# 编译到 windows 32bit
$ GOOS=windows GOARCH=386 go build

# 编译到 Mac OS X 64bit
$ GOOS=darwin GOARCH=amd64 go build

编译选项

-ldflags '-w -s'

-w 禁止生成debug信息,注意使用该选项后,无法使用 gdb 进行调试
-s 禁用符号表