Get the latest tech news

Building static binaries with Go on Linux


One of Go's advantages is being able to produce statically-linked binaries [1]. This doesn't mean that Go always produces such binaries by default, however; in some scenarios it requires extra work to make this happen.

This post goes over a series of experiments: we take simple programs and use go build to produce binaries on a Linux machine. If we build this program, we notice it's dynamically linked, expecting to load a libc shared object at run-time: These will produce statically-linked Go binaries; the zig driver takes care of setting the right linker flags automatically, so the command-line ends up being slightly simpler than invoking musl-gcc.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Linux

Linux

Photo of static binaries

static binaries

Related news:

News photo

The Current State Of CXL Support On Linux

News photo

Linux 6.11-rc1 Released With Initial Intel Battlemage Support, AMD RDNA4 Primed

News photo

An ordinary day with a Linux mobile device