diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 2ff748e8a085dc876046601776decd20d4a77d14..09905244b9758979b6d4bbf36f33aa91781d94d1 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -1164,7 +1164,7 @@ bool GFace::fillPointCloud(double maxDist, std::vector<SPoint3> *points,
 
 void GFace::lloyd(int nbiter, int infn)
 {
-#if defined(HAVE_MESH)
+#if defined(HAVE_MESH) && defined(HAVE_BFGS)
   lloydAlgorithm algo(nbiter, infn);
   algo(this);
 #endif
diff --git a/Mesh/meshGFaceLloyd.cpp b/Mesh/meshGFaceLloyd.cpp
index 7872cc2e00cab1e5867964f254ab23c2e2fd61eb..adacce0b5707fa2432bf98aba9f07adcca058aa3 100644
--- a/Mesh/meshGFaceLloyd.cpp
+++ b/Mesh/meshGFaceLloyd.cpp
@@ -1,4 +1,9 @@
 #include <set>
+#include <fstream>
+
+#include "GmshConfig.h"
+#if defined(HAVE_BFGS)
+
 #include "meshGFaceLloyd.h"
 #include "DivideAndConquer.h"
 #include "GFace.h"
@@ -8,13 +13,6 @@
 #include "Context.h"
 #include "meshGFace.h"
 #include "BackgroundMesh.h"
-#include <fstream>
-#include "ap.h"
-#include "alglibinternal.h"
-#include "alglibmisc.h"
-#include "linalg.h"
-#include "optimization.h"
-
 
 
 /****************fonction callback****************/
@@ -77,10 +75,6 @@ class gradientCallback {
 };
 
 
-void topology(const alglib::real_1d_array &x,double func,void *ptr){
-}
-
-
 
 /****************fonctions principales****************/
 /*****************************************************/
@@ -1152,3 +1146,4 @@ SPoint2 boundary_edge::get_p2(){
 }
 
 
+#endif
diff --git a/Mesh/meshGFaceLloyd.h b/Mesh/meshGFaceLloyd.h
index 90b2e426382ae5cdf9f5b62be3684581698beb97..b40bc46a9ec5673e5963183f79d9a79d35833c07 100644
--- a/Mesh/meshGFaceLloyd.h
+++ b/Mesh/meshGFaceLloyd.h
@@ -5,8 +5,12 @@
 
 #ifndef _MESH_GFACE_LLOYD_H_
 #define _MESH_GFACE_LLOYD_H_
+
 #include "fullMatrix.h"
 #include "DivideAndConquer.h"
+#include "GmshConfig.h"
+
+#if defined(HAVE_BFGS)
 #include "ap.h"
 #include "alglibinternal.h"
 #include "alglibmisc.h"
@@ -16,8 +20,6 @@
 class GFace;
 class boundary_edge;
 
-void topology(const alglib::real_1d_array &,double,void*);
-
 class lloydAlgorithm {
   int ITER_MAX;
   bool infiniteNorm;
@@ -101,3 +103,5 @@ class boundary_edge{
 };
 
 #endif
+
+#endif