diff --git a/configure b/configure
index 0b9479c60f6a30486dc896f8815c7df681873326..9e8f04d8008b5b31003c7e23a5ad9b6d74a5e7b7 100755
--- a/configure
+++ b/configure
@@ -3150,7 +3150,7 @@ if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   cat >> confdefs.h <<\EOF
 #define HAVE_LIBMESAGL 1
 EOF
- X_PRE_LIBS="$X_PRE_LIBS -lGL"
+ X_PRE_LIBS="$X_PRE_LIBS -lMesaGL"
 else
   echo "$ac_t""no" 1>&6
 fi
diff --git a/configure.in b/configure.in
index f63f0f97de207575f4a51ce0c61e269138956e86..5c7860b31e9c55b1eaedc74ced63d1b81a53ead3 100644
--- a/configure.in
+++ b/configure.in
@@ -154,7 +154,7 @@ then
             AC_CHECK_LIB(GL,glXCreateContext,AC_DEFINE(HAVE_LIBMESAGL) X_PRE_LIBS="$X_PRE_LIBS -lGL",,$X_LIBS -lXext -lX11 -lm)
 	    if test "$ac_cv_lib_GL_glXCreateContext" = "no"
 	    then
-		AC_CHECK_LIB(MesaGL,glXCreateContext,AC_DEFINE(HAVE_LIBMESAGL) X_PRE_LIBS="$X_PRE_LIBS -lGL",,$X_LIBS -lXext -lX11 -lm)
+		AC_CHECK_LIB(MesaGL,glXCreateContext,AC_DEFINE(HAVE_LIBMESAGL) X_PRE_LIBS="$X_PRE_LIBS -lMesaGL",,$X_LIBS -lXext -lX11 -lm)
 	    fi
         fi
     fi