Correctly link to libm and libdl on systems where it's needed.