Thursday, March 6, 2014

GO Cross-Compile for Raspberry Pi

Compiling GO on the Pi isn't simple or reliable, the easiest way I've found is to use cross-compilation.  This is where you compile on one system (e.g. mac) intended for another (e.g. raspbery-pi).  The compiled binary won't run on the originating system, but will run on the target system.

On the originating system, firstly you need to ensure GO's own libraries are prepared to perform the cross-compilation (normally it only prepares the ones for the system you're on):

Find where you downloaded GO and within the src folder run:
GOOS=linux GOARCH=arm GOARM=5 make.bash

You should see a number of additional libraries being compiled, you shouldn't need to do this again.

Now, go back to your GO project and run:
GOOS=linux GOARCH=arm GOARM=5 go build

The binary you just created can now be copied to the raspberry pi for execution

No comments:

Post a Comment