June 14, 2012

Go: Targeting a different architecture #golang

Posted in Software at 01:08 by graham

Problem: You’re on a i386 machine, and you need to build for amd64, or vice-versa.
Solution:

Get the libc for the other architecture. Get both, one of which you’ll already have:

# Debian / Ubuntu family
sudo apt-get install libc6-dev-amd64 libc6-dev-i386

Build the Go compiler for the other architecture:

cd $GOROOT/src
GOARCH=amd64 ./make.bash    # or GOARCH=386 for the other direction

Set the architecture before building your program:

GOARCH=amd64 go install <my_project>  # or GOARCH=386

The first two steps you only need to do once.

Thank you zephyrtronium in freenode#go-nuts for the help.

For other architectures, see Dave Cheney’s An introduction to cross compilation with Go

2 Comments »

  1. Daniel Hüsch said,

    December 18, 2012 at 05:32

    I just created two binaries for Linux on my Mac.

    GOOS=linux go build # 64 bits, as on my Mac itself GOOS=linux GOARCH=386 go build # 32 bits explicitly

  2. hasen said,

    July 28, 2012 at 04:12

    Thanks

    Would be nice if you also including how to target Ubuntu/Linux when working on OS X

Leave a Comment

Note: Your comment will only appear on the site once I approve it manually. This can take a day or two. Thanks for taking the time to comment.