Fixed the order of adding libs in the makefile. It was something of a nightmare.