diff --git a/pymusic/mpi_compat.h b/pymusic/mpi_compat.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b9f4b4316905845c7628647fb8fe27eb240a389
--- /dev/null
+++ b/pymusic/mpi_compat.h
@@ -0,0 +1,6 @@
+#include <mpi.h>
+
+#if (MPI_VERSION < 3) && !defined(PyMPI_HAVE_MPI_Message)
+typedef void *PyMPI_MPI_Message;
+#define MPI_Message PyMPI_MPI_Message
+#endif
diff --git a/pymusic/pybuffer.pxd b/pymusic/pybuffer.pxd
index f789c25803a20ce432bd7c31aa11034443705c9b..94aa5c66d2623f1a0047d9be792e18ba672f4782 100644
--- a/pymusic/pybuffer.pxd
+++ b/pymusic/pybuffer.pxd
@@ -1,3 +1,8 @@
+# The following include is needed to define a missing type MPI_Message
+# which is lacking for a certain combination of MPI and mpi4py versions
+cdef extern from "mpi_compat.h":
+    pass
+
 cimport mpi4py.MPI as MPI
 from mpi4py.mpi_c cimport *
 
diff --git a/pymusic/pymusic.pxd b/pymusic/pymusic.pxd
index dccdc76df8020efd5fc56234a274cf47e60d78e8..bf8261ed49d19f3782ad5ebe1fb6634bc5664fec 100644
--- a/pymusic/pymusic.pxd
+++ b/pymusic/pymusic.pxd
@@ -1,3 +1,8 @@
+# The following include is needed to define a missing type MPI_Message
+# which is lacking for a certain combination of MPI and mpi4py versions
+cdef extern from "mpi_compat.h":
+    pass
+
 cimport mpi4py.MPI as MPI
 from mpi4py.mpi_c cimport *