diff --git a/configure.ac b/configure.ac
index 2d394e1531bdbe90a7624e6e0bf8191330fc4460..5dfa83ef44423410040fa66299c1d96e1e369d84 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1137,10 +1137,17 @@ if test x"$want_gss" = xyes; then
     ],
     [
       dnl not found, check Heimdal or MIT
+      AC_CHECK_HEADERS([gssapi/gssapi.h], [], [not_mit=1])
       AC_CHECK_HEADERS(
-        [gssapi/gssapi.h gssapi/gssapi_generic.h gssapi/gssapi_krb5.h],
+        [gssapi/gssapi_generic.h gssapi/gssapi_krb5.h],
         [],
-        [not_mit=1])
+        [not_mit=1],
+        [
+AC_INCLUDES_DEFAULT
+#ifdef HAVE_GSSAPI_GSSAPI_H
+#include <gssapi/gssapi.h>
+#endif
+        ])
       if test "x$not_mit" = "x1"; then
         dnl MIT not found, check for Heimdal
         AC_CHECK_HEADER(gssapi.h,