Account for changes in boost dependencies

Since <boost/thread/thread.hpp> includes some headers which will already
call a boost_system function, recent versions of boost require
-lboost_system before -lboost_thread will work, resulting in a failure
of this test if not accounted for.

Make it try without -lboost_system first, but try again with it added to
$LIBS if that fails.