The new gcc needs to have the libraries at the end of the compile line.
Hence, to compile it on ubuntu 11.10 and up all you need to do is to add "-lm" to the end of the compile line. For example:
...