start | find | index | login or register | edit
2012-04-01
by earl, 4602 days ago
How to cross-compile Google Go (Language) programs:

The machines I work on are typically x64 boxes. A few x86 systems remain in my purview, however. Sometimes I want, on my x64 machine, cross-compile binaries to be used on legacy x86 systems. As finding how to do this with Go (1.x) took longer than necessary, here's the gist of it.

Prerequisite: you already have a Go toolchain for your native architecture installed.

First, install the x86 Go toolchain (compiler, linker, etc):

    $ go tool dist install -v cmd/8{a,c,g,l}
cmd/8a
cmd/8c
cmd/8g
cmd/8l

Second, install the x86 Go runtime:

    $ GOARCH=386 go tool dist install -v pkg/runtime
pkg/runtime (linux/386)

Now, you can cross-compile with plain go build by just setting the GOARCH environment variable to the desired target:

    $ GOARCH=386 go build hello.go


Repeat the same steps with 5{a,c,g,l} and GOARCH=arm, and you'll also be able to cross-compile to ARM.
powered by vanilla
echo earlZstrainYat|tr ZY @.
earl.strain.at • esa3 • online for 8662 days • c'est un vanilla site