diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 4fd087bacce538b022e6c92615ecf6e074053ee7..b2de8be27b217063bc8183bf5e7b8ae499cdc559 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -3,13 +3,18 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
+#include "GmshConfig.h"
+
+#if defined(HAVE_MPI)
+#include <mpi.h>
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
 #include <string.h>
 #include <time.h>
 #include <sys/stat.h>
-#include "GmshConfig.h"
 #include "GmshMessage.h"
 #include "GmshSocket.h"
 #include "Gmsh.h"
@@ -24,10 +29,6 @@
 #include "onelab.h"
 #endif
 
-#if defined(HAVE_MPI)
-#include <mpi.h>
-#endif
-
 #if defined(HAVE_PETSC)
 #include <petsc.h>
 #endif
diff --git a/Common/GmshRemote.cpp b/Common/GmshRemote.cpp
index 4116c39cdc95cf370d60f61bf5f4483b32e7182c..83b12456d7b730e51ff9ae266fe1f2d0263d61e1 100644
--- a/Common/GmshRemote.cpp
+++ b/Common/GmshRemote.cpp
@@ -3,8 +3,20 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
-#include <sstream>
 #include "GmshConfig.h"
+
+#if defined(HAVE_MPI)
+#include <mpi.h>
+#define MPI_GMSH_COMPUTE_VIEW  1
+#define MPI_GMSH_DATA_READY    2
+#define MPI_GMSH_VARRAY        3
+#define MPI_GMSH_VARRAY_LEN    4
+#define MPI_GMSH_SHUTDOWN      5
+#define MPI_GMSH_PARSE_STRING  6
+#define MPI_GMSH_MERGE_FILE    7
+#endif
+
+#include <sstream>
 #include "GmshMessage.h"
 
 #if defined(HAVE_ONELAB) && defined(HAVE_POST)
@@ -19,17 +31,6 @@
 #include "PViewData.h"
 #include "PViewDataRemote.h"
 
-#if defined(HAVE_MPI)
-#include <mpi.h>
-#define MPI_GMSH_COMPUTE_VIEW  1
-#define MPI_GMSH_DATA_READY    2
-#define MPI_GMSH_VARRAY        3
-#define MPI_GMSH_VARRAY_LEN    4
-#define MPI_GMSH_SHUTDOWN      5
-#define MPI_GMSH_PARSE_STRING  6
-#define MPI_GMSH_MERGE_FILE    7
-#endif
-
 static void computeAndSendVertexArrays(GmshClient *client, bool compute=true)
 {
   for(unsigned int i = 0; i < PView::list.size(); i++){
diff --git a/Solver/dofManager.cpp b/Solver/dofManager.cpp
index 77222fcfdb727288d80b2115ba3e0e5b68a4f5f7..a6fff9bf318ab466a416ef0ee1a4f52be19f53ae 100644
--- a/Solver/dofManager.cpp
+++ b/Solver/dofManager.cpp
@@ -3,13 +3,14 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
-#include <dofManager.h>
 #include "GmshConfig.h"
 
 #ifdef HAVE_MPI
 #include "mpi.h"
 #endif
 
+#include <dofManager.h>
+
 template<>
 void dofManager<double>::scatterSolution()
 {
diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp
index 1bf23e928207ba712e8b595c79843a3475f4717f..fd44f363e92974a61f48e32113ffbbc77ab3f540 100644
--- a/Solver/linearSystemPETSc.cpp
+++ b/Solver/linearSystemPETSc.cpp
@@ -4,13 +4,14 @@
 // bugs and problems to the public mailing list <gmsh@geuz.org>.
 
 #include "GmshConfig.h"
+#include <string.h>
+
 #if defined(HAVE_PETSC)
 #include "petsc.h"
 #include "linearSystemPETSc.h"
 #include "fullMatrix.h"
 #include <stdlib.h>
 #include "GmshMessage.h"
-
 #include "linearSystemPETSc.hpp"
 
 template class linearSystemPETSc<double>;
diff --git a/Solver/linearSystemPETSc.h b/Solver/linearSystemPETSc.h
index 246746dddd8e66926507eb2aaee39920fc91934b..ec8b666b07db2a3e049f90151a63edf0d97e224d 100644
--- a/Solver/linearSystemPETSc.h
+++ b/Solver/linearSystemPETSc.h
@@ -39,7 +39,9 @@
 #include "linearSystem.h"
 #include "sparsityPattern.h"
 #include "fullMatrix.h"
+#include <string.h>
 #include <vector>
+
 #if defined(HAVE_PETSC)
 
 #ifndef SWIG