My First Go Language Program on the Nokia #N900
On the Maemo users mailing list, there has been a discussion about the Go Programming Language. Various people have tried various things to get Go to work, so I thought I would take a crack at it and see what I could do with it.
Before I try installing something on my N900, I like to try and install it on my Ubuntu box. So, I followed the installation steps for Go to run natively under Ubuntu. I already had most of the C tools installed and I’ve been using Mercurial for some other projects, so getting set up was fairly easy. At the end of the install process, I received a message 2 known bugs; 0 unexpected bugs. Everything looked good to go.
I copied the sample Go program, complied and ran it without any difficulties. Nice.
My next step was to repeat the process in Scratchbox. Again, I had some of the C tools already installed, but I needed to install a few new ones. I did not have Mercurial installed, so I installed that, then I grabbed a copy of the repository and tried to build it. The build appeared to run fine until the very end when I received an error message saying gotest: line 184: qemu-arm: command not found
My hypothesis was that the build routine uses qemu-arm to test the build, and since I was running in Scratchbox, that was not necessary and generated a spurious error message. I tried to tweak the gotest routine, but without any success. So, I figured that a sufficient test would be to try compiling the sample program in Go in the Scratchbox.
The program complied and linked fine. However, when I tried to run it in Scratchbox, I received no output. Checking the directory, I found a brand new 71 meg core file. Well, that wasn’t promising.
Nonetheless, I hopped over to my N900. When I am testing on the N900, I use ssh to connect to it. I also use sshfs to mount files from my Ubuntu box. The compiled version of the sample Go program ran fine on the N900. The next step was to see if I could compile programs written in Go on the N900. I mounted the Go bin directory from Scratchbox on my Ubuntu machine to my N900. My first attempts at compiling failed with can’t find import: fmt. It took me a few times before I realized that the problem was that I hadn’t set $GOROOT properly. When I set $GOROOT to the right path and tried to compile, it worked properly. I then linked and ran the program without a hitch.
On the mailing lists, people had talked about problems getting the program written in Go to run. They talked about having to chmod the file to be executable and needing to copy it to /usr/bin. In my case, the program was properly flagged as executable from the linking process and it ran in any directory.
Others have spoken about trying to build the go compiler on the N900 itself. However, bison, which is one of the prerequisites is not readily currently available on the N900. Since I normally build packages in Scratchbox, it only seemed reasonable to me to build the compiler in Scratchbox on the Ubuntu box and then copy it across.
The basic compiler package ends up being about 15 Meg. Right now, I don’t see the need to carry the compiler around with me, so I’m just leaving it up on my Ubuntu box and mounting it when I want to play with it.
Looking through the documentation, it looks like there is a lot that you can build in Go right out of the box. Beyond that, there are lots of interesting external packages that can be added in, including support for XCB, sqlite, protocol buffers, OpenGL and so on. I’m not sure what combination of external packages would be the most valuable.
Finally, there is the question of whether or not yet another programming language is needed. Go seeks to be “a dynamic language like Python with the performance and safety of a compiled language like C or C++”. Sounds like a nice idea and so far, Go seems like a nice language. It is well worth experimenting with if you are an innovator or early adopter. On the other hand, I don’t expect the build procedures from Nokia to support Go packages in Maemo any time soon.
If you want to kick around Go on your N900 and don’t have a Scratchbox to build it in, let me know and I can zip up a tarball of my installation. If you’re doing something interesting with Go, especially on the N900, let me know. To me, the Go programming language is another fun geek’s tool for the N900, which is in my mind a great toy for geeks.