diff --git a/matlab/dynare.m b/matlab/dynare.m
index aea60ea5e470f24a4cdb47b2c9e13d58d13af380..27a1fe742af0bee09c925367488b01d700f7bd87 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -64,7 +64,11 @@ more off
 
 % sets default format for save() command
 if isoctave
-    default_save_options('-mat')
+    if octave_ver_less_than('3.8')
+        default_save_options('-mat')
+    else
+        save_default_options('-mat')
+    end
 end
 
 if nargin < 1
diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m
index d52edad9ff5fb9d86d9bbebcf930402b2287aa1c..4405c12e8ec9be0e8c7d243906d5e35a6ee6cb50 100644
--- a/matlab/dynare_config.m
+++ b/matlab/dynare_config.m
@@ -94,8 +94,9 @@ if isoctave || matlab_ver_less_than('7.4')
     addpath([dynareroot '/missing/ilu'])
 end
 
-% strjoin is missing in older versions of MATLAB and in Octave
-if isoctave || matlab_ver_less_than('8.1')
+% strjoin is missing in older versions of MATLAB and in Octave < 3.8
+if (isoctave && octave_ver_less_than('3.8')) || ...
+        (~isoctave && matlab_ver_less_than('8.1'))
     addpath([dynareroot '/missing/strjoin'])
 end
 
diff --git a/mex/build/octave/Makefile.am b/mex/build/octave/Makefile.am
index 4db708530dec61d6619218ac84b37ec1f54c9645..d2c49c847d8b651db48c95d6520334916c2208e7 100644
--- a/mex/build/octave/Makefile.am
+++ b/mex/build/octave/Makefile.am
@@ -2,7 +2,11 @@ ACLOCAL_AMFLAGS = -I ../../../m4
 
 # libdynare++ must come before gensylv, k_order_perturbation, dynare_simul_
 if DO_SOMETHING
-SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv qzcomplex ordschur block_kalman_filter sobol local_state_space_iterations linsolve
+SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv qzcomplex ordschur block_kalman_filter sobol local_state_space_iterations
+
+if COMPILE_LINSOLVE
+SUBDIRS += linsolve
+endif
 
 if HAVE_MATIO
 SUBDIRS += k_order_perturbation dynare_simul_
diff --git a/mex/build/octave/configure.ac b/mex/build/octave/configure.ac
index 0fba827a48dcde3032f071541f8480565ef788d9..135157fa8dd8a14bcd846058159676416e5000ac 100755
--- a/mex/build/octave/configure.ac
+++ b/mex/build/octave/configure.ac
@@ -31,8 +31,13 @@ if test "x$MKOCTFILE" != "x"; then
   FFLAGS=`$MKOCTFILE -p FFLAGS`
   CXXFLAGS=`$MKOCTFILE -p CXXFLAGS`
   LDFLAGS="`$MKOCTFILE -p LFLAGS` `$MKOCTFILE -p LDFLAGS`"
+  OCTAVE_VERSION=`$MKOCTFILE -v 2>&1 | sed 's/mkoctfile, version //'`
+  AX_COMPARE_VERSION([$OCTAVE_VERSION], [lt], [3.6], [AC_MSG_ERROR([Your Octave is too old, please upgrade to version 3.6 at least.])])
+  AX_COMPARE_VERSION([$OCTAVE_VERSION], [ge], [3.8], [OCTAVE38=yes])
 fi
 
+AM_CONDITIONAL([COMPILE_LINSOLVE], [test "$OCTAVE38" != "yes"])
+
 CFLAGS="$CFLAGS -Wall -Wno-parentheses"
 FFLAGS="$FFLAGS -Wall"
 CXXFLAGS="$CXXFLAGS -Wall -Wno-parentheses"
@@ -101,6 +106,12 @@ else
    BUILD_MS_SBVAR_MEX_OCTAVE="no (missing GSL or MatIO library)"
 fi
 
+if test -n "$MKOCTFILE" -a "$OCTAVE38" != "yes"; then
+   BUILD_LINSOLVE_OCTAVE="yes"
+else
+   BUILD_LINSOLVE_OCTAVE="no (Octave >= 3.8)"
+fi
+
 AC_ARG_ENABLE([openmp], AS_HELP_STRING([--enable-openmp], [use OpenMP for parallelization of some MEX files]), [
   if test "x$enable_openmp" = "xyes"; then
     CPPFLAGS="$CPPFLAGS -DUSE_OMP"
@@ -118,6 +129,7 @@ Binaries (with "make"):
  MS-SBVAR MEX files for Octave:                                      $BUILD_MS_SBVAR_MEX_OCTAVE
  Kalman Steady State MEX file for Octave:                            $BUILD_KALMAN_STEADY_STATE_OCTAVE
  k-order and dynare_simul MEX for Octave:                            $BUILD_ESTIMATION_KORDER_DYNSIMUL_MEX_OCTAVE
+ Linsolve for Octave:                                                $BUILD_LINSOLVE_OCTAVE
 
 ])
 
diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh
index 2a28c3dce9609e2c355823e2a1320713dba95371..6e2024a378e8cedeacfd558d3b181f0f277f50ea 100644
--- a/mex/sources/bytecode/ErrorHandling.hh
+++ b/mex/sources/bytecode/ErrorHandling.hh
@@ -267,9 +267,6 @@ struct s_plan
 
 #ifdef MATLAB_MEX_FILE
 extern "C" bool utIsInterruptPending();
-#else
-#include <octave/oct.h>
-#include <octave/unwind-prot.h>
 #endif
 
 #ifdef _MSC_VER
@@ -575,9 +572,7 @@ public:
 
     while (go_on)
       {
-#ifdef OCTAVE_MEX_FILE
-        OCTAVE_QUIT;
-#else
+#ifdef MATLAB_MEX_FILE
 	      if ( utIsInterruptPending() )
 		      throw UserExceptionHandling();
 #endif
diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc
index 89b79ef8712d998ac0450199defbe1a1f2a9b358..76aec3b1b650765f9e9030666e4c6ec30671aac5 100644
--- a/mex/sources/bytecode/Evaluate.cc
+++ b/mex/sources/bytecode/Evaluate.cc
@@ -24,9 +24,6 @@
 
 #ifdef MATLAB_MEX_FILE
 extern "C" bool utIsInterruptPending();
-#else
-#include <octave/oct.h>
-#include <octave/unwind-prot.h>
 #endif
 
 Evaluate::Evaluate()
@@ -139,9 +136,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int
           jacob_exo_det = mxGetPr(jacobian_det_exo_block[block_num]);
         }
     }
-#ifdef OCTAVE_MEX_FILE
-  OCTAVE_QUIT;
-#else
+#ifdef MATLAB_MEX_FILE
 	if ( utIsInterruptPending() )
 		throw UserExceptionHandling();
 #endif
diff --git a/mex/sources/bytecode/SparseMatrix.cc b/mex/sources/bytecode/SparseMatrix.cc
index 70226a7983f3dad6373774bc88356f72557b91df..9cc45e45407dafd62d8d909dc6d20e162dc91ffd 100644
--- a/mex/sources/bytecode/SparseMatrix.cc
+++ b/mex/sources/bytecode/SparseMatrix.cc
@@ -5139,9 +5139,7 @@ dynSparseMatrix::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(int Size, bo
     {
       /*clock_t time11 = clock();
       mexPrintf("t=%d, record = %d\n",t, record);*/
-#ifdef OCTAVE_MEX_FILE
-      OCTAVE_QUIT;
-#else
+#ifdef MATLAB_MEX_FILE
     	if ( utIsInterruptPending() )
 		    throw UserExceptionHandling();
 #endif