## Thursday, November 19, 2009

### Installing Google Go on Mac OS X

I decided to have a go with Google Go since I'm an old fogey C/C++ programmer. Any new innovation in the C/C++ family gets me excited and Google Go has quite a few nice features (garbage collection is really nice to have and channels make me think of all the work I did in CSP).

I decided to go with the 6g compiler since gccgo doesn't have garbage collection implemented yet and hence there's no way to free memory. The only way to get 6g is to mirror its Mercurial repository. So...

Step 1: Install Mercurial

For that I used prebuilt packages from here and got Mercurial 1.4 for Mac OS X 1.5 (no, I haven't upgraded to Snow Leopard yet).

Step 2. Set GOROOT

I just did a quick cd ; mkdir go ; export GOROOT=$HOME/go to get me started. Step 3. Clone the 6g repository That was a quick hg clone -r https://go.googlecode.com/hg/$GOROOT followed by the hard part: compiling it. You need to have gcc, make, bison and ed installed (whcih I do since I do development work on my Mac).

Step 5. Set GOBIN

This points to where the binaries will go, for me that's $HOME/bin since I'll be doing local development using Go. And I updated PATH to include$GOBIN.

Step 4. Compile 6g

You first need to set GOARCH and GOOS. For me that's amd64 for the architecture (the Intel Core 2 Duo in my Macbook Air is a 64-bit processor) and darwin for the OS (since this is a Mac).
$export GOARCH=amd64$ export GOOS=darwin

Then you can actually do the compile:
$cd$GOROOT/src$./all.bash This does a build and test of 6g and it was very fast to build (although I'm used to building gcc which is a bit of a monster). Step 5. Write a Hello, World! program Here's my first little Google Go program (filename: hw.go) just to test the 6g compiler. package mainimport "fmt"func main() { fmt.Printf( "Hello, World\n" );} To simplify building I made a minimal Makefile: all: hwhw: hw.6 ; 6l -o$@ $^%.6: %.go ; 6g$<

And then the magic moment:
$make6g hw.go6l -o hw hw.6$ ./hwHello, World!

And now for a real project... get SQLite to interface to it.

Labels: ,

If you enjoyed this blog post, you might enjoy my travel book for people interested in science and technology: The Geek Atlas. Signed copies of The Geek Atlas are available.

<$BlogCommentBody$>

<$BlogCommentDateTime$> <$BlogCommentDeleteIcon$>

<$BlogBacklinkControl$> <$BlogBacklinkTitle$> <$BlogBacklinkDeleteIcon$>
<$BlogBacklinkSnippet$>