Fix library linking order for Debian and Ubuntu