Compile with -Wl,--as-needed.