diff --git a/autoconf.mk.in b/autoconf.mk.in
index 2836b4f1..cbf57efc 100644
--- a/autoconf.mk.in
+++ b/autoconf.mk.in
@@ -23,7 +23,6 @@ LIBS=@LIBS@
 CPPFLAGS=@CPPFLAGS@
 CXX=@CXX@
 CXXFLAGS=@CXXFLAGS@ $(CXXWFLAGS) $(WFLAGS) -DPOINTERHOLDER_TRANSITION=2
-RPATH=@RPATH@
 AR=@AR@
 RANLIB=@RANLIB@
 DLLTOOL=@DLLTOOL@
diff --git a/configure b/configure
index 3118deed..7e715abf 100755
--- a/configure
+++ b/configure
@@ -670,7 +670,6 @@ PKG_CONFIG
 WINDOWS_WORDSIZE
 IS_32BIT
 RANDOM_DEVICE
-RPATH
 LT_SONAME
 LT_AGE
 LT_REVISION
@@ -16353,10 +16352,17 @@ fi
 if test "$qpdf_USE_RPATH" = "1"; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
-   RPATH='-rpath $(libdir)'
 else
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+   if test "${hardcode_libdir_flag_spec/rpath/}" != "$hardcode_libdir_flag_spec"; then
+      hardcode_libdir_flag_spec=
+   fi
+   runpath_var=
+   if test "${hardcode_libdir_flag_spec_CXX/rpath/}" != "$hardcode_libdir_flag_spec_CXX"; then
+      hardcode_libdir_flag_spec_CXX=
+   fi
+   runpath_var_CXX=
 fi
 
 
diff --git a/configure.ac b/configure.ac
index 612a049b..ace0543f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,11 +72,17 @@ AC_ARG_ENABLE(rpath,
     fi], [qpdf_USE_RPATH=1])
 if test "$qpdf_USE_RPATH" = "1"; then
    AC_MSG_RESULT(yes)
-   RPATH='-rpath $(libdir)'
 else
    AC_MSG_RESULT(no)
+   if test "${hardcode_libdir_flag_spec/rpath/}" != "$hardcode_libdir_flag_spec"; then
+      hardcode_libdir_flag_spec=
+   fi
+   runpath_var=
+   if test "${hardcode_libdir_flag_spec_CXX/rpath/}" != "$hardcode_libdir_flag_spec_CXX"; then
+      hardcode_libdir_flag_spec_CXX=
+   fi
+   runpath_var_CXX=
 fi
-AC_SUBST(RPATH)
 
 AC_MSG_CHECKING(for -fvisibility=hidden)
 try_flags=-fvisibility=hidden
diff --git a/make/libtool.mk b/make/libtool.mk
index 2ff96f86..c9ed6b3b 100644
--- a/make/libtool.mk
+++ b/make/libtool.mk
@@ -95,7 +95,7 @@ define makelib
 	$(LIBTOOL) --mode=link --tag=CXX \
 		$(CXX) $(CXXFLAGS) $(LD_VERSION_FLAGS) \
 		 -o $(2) $(1) $(3) $(4) \
-		 $(RPATH) -version-info $(5):$(6):$(7) -no-undefined
+		 -rpath $(libdir) -version-info $(5):$(6):$(7) -no-undefined
 endef
 
 #                       1    2      3       4    5
