GoLang

This is a small Wiki page about the golang package on Maemo. The package contains the standalone go compiler and libraries targeting armv6.

[edit] Creating a Hello world application using the go programming language

Creating a Hello world application using the go language on the N900. The go compiler and libraries for Maemo are packaged in a package called golang that can be installed from the fremantle/free repository. The package puts all its content in a directory called /opt/go to follow Maemo packaging policies.

Once the package is installed we need to set a few environments variables to make the go compiler happy.

Those are:

export GOROOT=/opt/go
export GOOS=linux
export GOARCH=arm
export GOBIN=/opt/go/bin
export GOPKG=/opt/go/pkg
PATH=$PATH:$GOBIN

The packager provides a script to to this that can be sourced

~ $ . /opt/go/bin/go_profile


Now off to create Hello world. We will create a directory in the users home directory create a small go hello world file, compile, link and run it.

Creating the directory using mkdir

mkdir hello_go

Go into that directory and fire up an editor

cd hello_go
vi hello.go

Paste the following

package main
 
import "fmt"
 
func main() {
  fmt.Printf("Hello, Maemo\n")
}


exit vi and compile hello.go

~/hello_go $ 5g hello.go

Link it against the go libs (the output is a staticaly linked binary)

~/hello_go $ 5l hello.5

and now run it

~/hello_go $ ./5.out
Hello, Maemo

If all went well you just ran your first go code on Maemo!