Go: Targeting a different architecture #golang
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