Compiling Go to run on Android on a Nexus S
Originally posted on Google Plus on 2012-01-17.
It turns out to be really easy to cross compile Go. The Go build instructions are at http://golang.org/doc/install.html . I built Go like this on an Ubuntu 8.04 i686 :
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
env | grep '^GO'
I note that the tests failed and I have not investigated. The build may not be be entirely correct.
The Nexus S uses ARMv7 instructions. Another phone may not so maybe use
I took a Go source file I had named map-1.go and compiled it using:
5g map-1.go && 5l -o map-1 map-1.5
file map-1 shows it is an ARM file:
map-1: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
Now transfer it to a Nexus S as /sdcard/map-1 . "adb push" or mounting as a USB drive will work. I did not have either so I used Opera to download from an HTTP server.
It turns out /sdcard is mounted noexec . I should find a place to put binaries from development but for trying it out now I just:
mount -o remount /mnt/sdcard
And run it:
The binary runs successfully!