--- configure
+++ configure
@@ -34,6 +34,7 @@
 then
   HAVE_LIBIBERTY=1
   echo "yes"
+  LIBS="$LIBS -liberty"
 else
   unset HAVE_LIBIBERTY
   echo "no"
@@ -52,6 +53,7 @@
 then
   HAVE_LIBSUPC__=1
   echo "yes"
+  LIBS="$LIBS -lsupc++"
 else
   unset HAVE_LIBSUPC__
   echo "no"
@@ -67,7 +69,7 @@
   return 0;
 }
 EOF
-if $CC conftest.c 2>/dev/null
+if $CC conftest.c -lelf 2>/dev/null
 then
   HAVE_ELF_C_READ_MMAP=1
   echo "yes"
@@ -78,7 +80,7 @@
 rm -f conftest.c a.out
 
 CFLAGS='-g -O2'
-LIBS='-lelf -lsupc++ -liberty '
+LIBS="$LIBS -lelf"
 INSTALL='$/usr/bin/install -c'
 iquote='-iquote '
 iquoteend=''
