Link binaries with -Wl,--as-needed to reduce library dependencies
Using pkg-config --libs to get library link lines has the disadvantage
of bringing in many more library dependencies than actually necessary,
since that assumes that dependencies of libraries need to be specified
explicitly at link time (even when the library is itself linked against
those dependencies). Using GNU ld's --as-needed option causes these
unnecessary dependencies to be omitted from the binary.
--as-needed needs to be specified after all the objects to be linked
into the binary and before the libraries, so some reordering of the link
command line is needed.