added extra checks for find_header and have_library if pkg_config fails
added missing includes and remove a possible segfault in 'a' + i