diff --git a/m4/mgetgroups.m4 b/m4/mgetgroups.m4
index 5747148..7e11085 100644
--- a/m4/mgetgroups.m4
+++ b/m4/mgetgroups.m4
@@ -19,7 +19,8 @@ AC_DEFUN([gl_MGETGROUPS],
             [[#if HAVE_GRP_H
                #include <grp.h>
               #endif
-              int groups[1];
+              #include <unistd.h>
+              gid_t groups[1];
               int ngroups = 1;
             ]],
             [[return - getgrouplist ("root", 0, groups, &ngroups);]])],
@@ -29,6 +30,7 @@ AC_DEFUN([gl_MGETGROUPS],
               [[#if HAVE_GRP_H
                  #include <grp.h>
                 #endif
+                #include <unistd.h>
                 int groups[sizeof (gid_t) == sizeof (int) ? 1 : -1];
                 int ngroups = 1;
               ]],
