diff --git a/m4/ax_slicot.m4 b/m4/ax_slicot.m4
index b53e64480ccdace61067c52feaba554707897578..ae9793693d94d25753c75c8979ef51a703288d6e 100644
--- a/m4/ax_slicot.m4
+++ b/m4/ax_slicot.m4
@@ -37,7 +37,7 @@ AC_DEFUN([AX_SLICOT],
   else
     LDFLAGS_SLICOT=""
   fi
-  ac_save_LDFLAGS=$LDFLAGS
+  my_save_LDFLAGS=$LDFLAGS
 
   # At this point we should add MATLAB_FCFLAGS to FCFLAGS for Windows (which has -fno-underscoring),
   # but that does not work. The actual underscore test seems to happen at the very beginning of the
@@ -47,9 +47,13 @@ AC_DEFUN([AX_SLICOT],
   if test "$1" = matlab; then
     LDFLAGS="$LDFLAGS $MATLAB_LDFLAGS_NOMAP $LDFLAGS_SLICOT"
 
+    # Add MATLAB_CFLAGS to get the -fPIC on Linux/x86_64 (otherwise linking fails)
+    my_save_CFLAGS=$CFLAGS
+    CFLAGS="$CFLAGS $MATLAB_CFLAGS"
     AC_CHECK_LIB([slicot64_pic], [$sb02od], [LIBADD_SLICOT="-lslicot64_pic"], [has_slicot=no], [$MATLAB_LIBS])
+    CFLAGS=$my_save_CFLAGS
   else
-    LDFLAGS="$LDFLAGS $($MKOCTFILE -p LFLAGS) $LDFLAGS_SLICOT"
+    LDFLAGS="$LDFLAGS $LDFLAGS_SLICOT"
     # Fallback on libslicot_pic if dynamic libslicot not found
     AC_CHECK_LIB([slicot], [$sb02od], [LIBADD_SLICOT="-lslicot"],
              [
@@ -58,7 +62,7 @@ AC_DEFUN([AX_SLICOT],
              [$($MKOCTFILE -p BLAS_LIBS) $($MKOCTFILE -p LAPACK_LIBS)])
   fi
 
-  LDFLAGS=$ac_save_LDFLAGS
+  LDFLAGS=$my_save_LDFLAGS
   AC_SUBST(LDFLAGS_SLICOT)
   AC_SUBST(LIBADD_SLICOT)
 ])
diff --git a/mex/build/matlab/configure.ac b/mex/build/matlab/configure.ac
index bab4ac5ccf39c47867efbd70c437df7cc9d9fde8..97b0eabd4962a5162a1c175588ad091f747c3059 100644
--- a/mex/build/matlab/configure.ac
+++ b/mex/build/matlab/configure.ac
@@ -88,10 +88,10 @@ if test "$enable_mex_kalman_steady_state" = yes; then
   # FCFLAGS must be temporarily modified, because otherwise -fno-underscoring is not
   # taken into account by AC_FC_FUNC in the AX_SLICOT macro.
   # For some obscure reason, it is necessary to do it at this level and not within the macro.
-  ac_save_FCFLAGS=$FCFLAGS
+  my_save_FCFLAGS=$FCFLAGS
   FCFLAGS="$FCFLAGS $MATLAB_FCFLAGS"
   AX_SLICOT([matlab])
-  FCFLAGS=$ac_save_FCFLAGS
+  FCFLAGS=$my_save_FCFLAGS
   test "$has_slicot" != yes && AC_MSG_ERROR([slicot cannot be found. If you want to skip the compilation of the kalman_steady_state MEX, pass the --disable-mex-kalman-steady-state flag.])
 fi