Add -lm and place linked libraries after object on gcc cmdline.

On Ubuntu 13.04 with gcc 4.7.3 it requires libraries to be specified after objects on the command line. Otherwise you'll get lots of undefined references.

Also added missing math library.