Go, build for a different architecture

It happened that I needed to (re)build a small program for an i386 machine. This was about the same time I realized we still had those… It’s very easy but since I’ll not be using this a lot I wanted to document it.

First of all, build the correct Go compiler. I’m on (Ubuntu) amd64 and these instructions explain how to get the i386 build. (you can replace all (i)386 with amd64 to do the reverse..)

Install correct libc6-dev

This is not so hard: sudo apt-get install libc6-dev-i386

Build Go for i386

I’m assuming you did a binary install of golang, in that case you just need to find the make.bash script in the src dir like this.

harkx:~$ cd /usr/local/go/src
harkx:/usr/local/go/src$ sudo GOARCH=386 ./make.bash
# Building C bootstrap tool.

When finished you’ll get something like this:

Installed Go for linux/386 in /usr/local/go

Installed commands in /usr/local/go/bin

Build application

That’s it. Now you can build your application for i386 like this:

harkx:~$ GOARCH=386 go build myapp.go

And look at the result:

harkx:~$ file ./myapp
./myapp: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped

Resources:

written by @harkx

comments powered by Disqus