diff --git a/configure b/configure
index cafcbc3fd17b5c0643dd4a305f3aae44409ef635..e876c93995d42bc4a67a6187ae2a0fd82006c5ba 100755
--- a/configure
+++ b/configure
@@ -5758,6 +5758,66 @@ fi
 
 # first look for blas
 if test "$external_blas" == true ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether dgemv can be linked with no library" >&5
+$as_echo_n "checking whether dgemv can be linked with no library... " >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dgemv ();
+int
+main ()
+{
+return dgemv ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+    blas_found=nounderscore
+
+else
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether dgemv_ can be linked with no library" >&5
+$as_echo_n "checking whether dgemv_ can be linked with no library... " >&6; }
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dgemv_ ();
+int
+main ()
+{
+return dgemv_ ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+      blas_found=underscore
+
+else
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
   if test "${libsearch}" == true ; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dgemv" >&5
@@ -6115,6 +6175,14 @@ fi
 
   fi
 
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 # if not found, then use internal lapack and blas
diff --git a/configure.ac b/configure.ac
index 582cb0da1607f3812a89fffd95a70f5a78c38dcb..8419df86f2e35dd79148a81b0c0f81a65dba4755 100644
--- a/configure.ac
+++ b/configure.ac
@@ -487,8 +487,22 @@ fi
 
 # first look for blas
 if test "$external_blas" == true ; then
-  PLUMED_SEARCH_LIBS([dgemv],[blas],[blas_found=nounderscore], [
-    PLUMED_SEARCH_LIBS([dgemv_],[blas],[blas_found=underscore])
+  AC_MSG_CHECKING([whether dgemv can be linked with no library])
+  AC_LINK_IFELSE([AC_LANG_CALL([], [dgemv])],[
+    AC_MSG_RESULT([yes])
+    blas_found=nounderscore
+    ],[
+    AC_MSG_RESULT([no])
+    AC_MSG_CHECKING([whether dgemv_ can be linked with no library])
+    AC_LINK_IFELSE([AC_LANG_CALL([], [dgemv_])],[
+      AC_MSG_RESULT([yes])
+      blas_found=underscore
+    ],[
+      AC_MSG_RESULT([no])
+      PLUMED_SEARCH_LIBS([dgemv],[blas],[blas_found=nounderscore],[
+        PLUMED_SEARCH_LIBS([dgemv_],[blas],[blas_found=underscore])
+      ])
+    ])
   ])
 fi