Reorganise library version detection, adds tentative fix for clang with libstdc++.  See issues 10600 and 7473