diff --git a/src/modules/Gmp/next_prime.c b/src/modules/Gmp/next_prime.c
index 097a9bdd677e5c8a0f9d8eb4ab5b63d16d300b71..660fbc76e8ad058ef293bd34f9d7a23dac92439c 100644
--- a/src/modules/Gmp/next_prime.c
+++ b/src/modules/Gmp/next_prime.c
@@ -7,6 +7,15 @@
  * with Gmp-2.1 .
  */
 
+#include "gmp_machine.h"
+
+#if !defined(HAVE_LIBGMP)
+#undef HAVE_GMP_H
+#endif
+
+
+#ifdef HAVE_GMP_H
+
 #include <limits.h>
 #include <gmp.h>
 
@@ -195,3 +204,5 @@ mpz_next_prime(mpz_t p, mpz_t n, int count, int prime_limit)
     }
   mpz_clear(tmp);
 }
+
+#endif