ensure -lX libraries are linked in last, not according to their order in the inputs; fixes regression from 6556a69f282ec534512c3e6a119328fe98886a97