Skip navigation.
Home

Writing Google Go Apps

Writing programs

Given a file file.go, compile it using

$ 6g file.go

6g is the Go compiler for amd64; it will write the output in file.6. The ‘6’ identifies files for the amd64 architecture. The identifier letters for 386 and arm are ‘8’ and ‘5’. That is, if you were compiling for 386, you would use 8g and the output would be named file.8.

To link the file, use

$ 6l file.6

and to run it

$ ./6.out

A complete example:

$ cat >hello.go <<EOF
package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}
EOF
$ 6g hello.go
$ 6l hello.6
$ ./6.out
hello, world
$

There is no need to list hello.6's package dependencies (in this case, package fmt) on the 6l command line. The linker learns about them by reading hello.6.

To build more complicated programs, you will probably want to use a Makefile. There are examples in places like $GOROOT/src/cmd/godoc/Makefile and $GOROOT/src/pkg/*/Makefile. The document about contributing to the Go project gives more detail about the process of building and testing Go programs.