Tuesday, December 27, 2005

The Christmas of code

I was mostly working through Christmas. As opposed to the popular public celebrations in Asia during this time, most of America seems to celebrate X'mas at home with family and the streets are all but deserted. The Yuletide spirit did, however, rain down a lot of programming goodies onto me.

I had been searching forever for a good math library for C++ which could provide me things like probability distribution tables, linear algebra and the like, and a couple of days ago I discovered the GNU Scientific Library (GSL). Its an extremely thorough, well-documented and well-implemented library (in terms of API) for C/C++. Its a huge surprise this doesn't turn up if you google for c++ statistical library or c++ numeric computing. It has routines for all kinds of scientific computations from Fast Fourier Transforms to Statistical Distributions to Monte Carlo Integration. An amazing find. Shouldn't they be required to tell you about such stuff in graduate school, if not as an undergraduate?

I finally made myself reasonably conversant with creating Makefiles for gcc. Creating makefiles for your project manually however is difficult since the dependencies inside your code may change and thus play havoc with incremental builds. I could not, however, make myself learn autoconf and automake - for which there's a whole book - next to which the GNU Make manual looks like a short story. I decided instead to try and write a small piece of software which would generate makefiles automatically for simple projects. I ended up writing a small bash script, which I call buildmake, which basically does what I need - takes a bunch of cpp files, resolves header file dependencies and creates a makefile for incremental builds. If you're into that sort of thing, you can check it out here.

To complete the trio, I had been frustrated in my attempts to get Mac OS X to link static libraries with programs (I know, dynamic libraries are the "in" thing, but you try and convince your cluster administrator to give you access to /usr/lib); and I finally figured out the problem which left me kicking myself and (nearly) my laptop. Turns out that for Apple's GCC, the order of linking is important: gcc -lsomelib code.c will not work, but gcc code.c -lsomelib will. Now, I had tried to export environment variables, copy libraries to all sorts of places, explored unchartered GCC flags, but who would have thought of that! And nope, Google is not your friend if you have this problem either - found this nugget of information in what has now become my favourite book, despite the cheesy name - Mac OS X Tiger for Unix geeks.

Hope you all had a merry Christmas!