Skip to main content

Posts

Showing posts from June, 2014

cross-compile go code, including cgo

By all means cross-compiling a new language/stack is not going to be pretty, but it didn't turn out that bad. A few weeks back, I was told that go code which uses cgo (that is utilising C api calls to shared libraries exporting C interface) cannot be cross-compiled. Well, if it's just calling out a C compiler it should totally be easy to cross compile, since so much of our platform is. So there we go, first I've picked a moderately small project which only does a couple cgo calls, and check that it compiles correctly: $ sudo apt-get build-dep ubuntu-push-client $ go get launchpad.net/ubuntu-push/... $ cd $GOPATH/src/launchpad.net/ubuntu-push/ $ go build ubuntu-push-client.go Well, when your gcc is all is easy. I didn't want to polute my system, so I quickly created a chroot with go, build-dependencies in armhf architectures and cross-compiler: # Get a chroot with build-dependencies installed, I am basing on top of a click-chroot # one should be able to use