Go

Goでスタティックバイナリにするオプション

備忘録

https://github.com/golang/go/issues/26492#issuecomment-435462350


We build golang binaries across a variety of platforms, preferring static builds wherever possible. Here are the flags we're currently using:

windows: -tags netgo -ldflags '-H=windowsgui -extldflags "-static"'

linux/bsd: -tags netgo -ldflags '-extldflags "-static"'

macos: -ldflags '-s -extldflags "-sectcreate __TEXT __info_plist Info.plist"'

android: -ldflags -s

On macos and android, we need to be able to pull in system frameworks and libraries so we opted not to build static binaries.


Linuxの例

$ go install -tags netgo -ldflags '-extldflags "-static"'