Don't use the hard-coded libmysqlclient_r name for the client library, because it is obsolete in 5.7. Instead, if the client library path is specified explicitly with --with-mysql-libs, try both libmysqlclient_r and libmysqlclient in that order.