Skip to content

Using `musl` to get a completely static binary

Tobias Schottdorf edited this page Dec 11, 2015 · 3 revisions

Static Build With musl

musl is an implementation of libc. When linking against it instead of glibc (on Linux systems), a completely static binary can be produced with some caveats.

  1. This has not been tested (for correctness or performance)
  2. The netgo build tag must be used (musls resolver does not work in some situations).
  3. Use the following settings:
 CC = /usr/local/musl/bin/musl-gcc
 # `-v` so warnings from the linker aren't suppressed.
 # `-a` so dependencies are rebuilt (they may have been dynamically
 # linked).
 GOFLAGS += -a -v
 LDFLAGS += -extldflags '-static'

See #3413 and referenced commits for tracing the work done on this. It was abandoned since linking glibc dynamically seemed acceptable. It is very unwise to try to link glibc statically.

  • Home
  • Beta Dashboard
  • Release Process
  • [Building and running tests](Building and running tests)
    • [Using musl to get a completely static binary](Using musl to get a completely static binary)
  • Productivity
    • [Multiple GOPATHs](Multiple GOPATHs)
    • [Ben's Go Emacs setup](Ben's Go Emacs setup)
    • [Radu's vim setup](Radu's vim setup)
    • [Speeding up cgo builds](Speeding up cgo builds)
    • [Rando scripts](Rando scripts)
  • [Life of a transaction](Life of a transaction)
  • Readings
Clone this wiki locally