Cross Compiling Go Application for Raspberry Pi

Cross Compiling Go Programs for Raspberry Pi

Lets write a simple hello world program

package main

import "fmt"

func main() {
  fmt.Println("Hello World")
}

Inside the project directory run the following command. This will create a binary compatible with raspberry pi.

env GOOS=linux GOARCH=arm GOARM=5 go build

Now you can copy it to the raspberrypi using scp

This will copy helloworld binary to the home directory

scp helloworld pi@raspberrypi.local:

Copy the file to the /home/pi/project/ directory on your Raspberry Pi (the project folder must already exist):

scp helloworld pi@raspberrypi.local:project/

Note: You can use the ip address of the raspberry pi.