--- a/acinclude.m4
+++ b/acinclude.m4
@@ -386,9 +386,9 @@ AC_DEFUN([LIBSSH2_CHECKFOR_MBEDTLS], [
 
   old_LDFLAGS=$LDFLAGS
   old_CFLAGS=$CFLAGS
-  if test -n "$use_mbedtls" && test "$use_mbedtls" != "no"; then
-    LDFLAGS="$LDFLAGS -L$use_mbedtls/lib"
-    CFLAGS="$CFLAGS -I$use_mbedtls/include"
+  if test -n "$with_libmbedtls_prefix" && test "$use_mbedtls" != "no"; then
+    LDFLAGS="$LDFLAGS -L$with_libmbedtls_prefix/lib"
+    CFLAGS="$CFLAGS -I$with_libmbedtls_prefix/include"
   fi
 
   AC_LIB_HAVE_LINKFLAGS([mbedtls], [], [
@@ -412,9 +412,9 @@ AC_DEFUN([LIBSSH2_CHECKFOR_GCRYPT], [
 
   old_LDFLAGS=$LDFLAGS
   old_CFLAGS=$CFLAGS
-  if test -n "$use_libgcrypt" && test "$use_libgcrypt" != "no"; then
-    LDFLAGS="$LDFLAGS -L$use_libgcrypt/lib"
-    CFLAGS="$CFLAGS -I$use_libgcrypt/include"
+  if test -n "$with_libgcrypt_prefix" && test "$use_libgcrypt" != "no"; then
+    LDFLAGS="$LDFLAGS -L$with_libgcrypt_prefix/lib"
+    CFLAGS="$CFLAGS -I$with_libgcrypt_prefix/include"
   fi
   AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [
     #include <gcrypt.h>
