Re-worked library linking pipeline

This should make things compile on Ubuntu as well. I don't understand this fully, but it seems that Ubuntu has trouble linking C libraries later, and Fedora doesn't...