From 9d32204790dc073265db41a8ed9cad08811f1518 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 10 Mar 2014 17:25:39 +0100
Subject: [PATCH] Ensure that -lpthread is statically linked under MinGW.

---
 configure.ac                  | 6 ++++++
 mex/build/matlab/configure.ac | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/configure.ac b/configure.ac
index 2620d82476..60b946a3c7 100755
--- a/configure.ac
+++ b/configure.ac
@@ -163,6 +163,12 @@ fi
 AM_CONDITIONAL([HAVE_BLAS], [test x"$ax_blas_ok" = "xyes"])
 AM_CONDITIONAL([HAVE_LAPACK], [test x"$ax_lapack_ok" = "xyes"])
 
+case ${host_os} in
+  *mingw32*)
+    # Ensure that -lpthread is statically linked under MinGW
+    PTHREAD_LIBS="-Wl,-Bstatic -lpthread -Wl,-Bdynamic"
+    ;;
+esac
 AX_PTHREAD
 
 AC_CONFIG_FILES([Makefile
diff --git a/mex/build/matlab/configure.ac b/mex/build/matlab/configure.ac
index 0e43b3995b..f7a668f289 100644
--- a/mex/build/matlab/configure.ac
+++ b/mex/build/matlab/configure.ac
@@ -60,7 +60,15 @@ AC_PROG_RANLIB
 AX_PROG_LN_S
 AC_PROG_MKDIR_P
 AM_PROG_AR
+
+case ${host_os} in
+  *mingw32*)
+    # Ensure that -lpthread is statically linked under MinGW
+    PTHREAD_LIBS="-Wl,-Bstatic -lpthread -Wl,-Bdynamic"
+    ;;
+esac
 AX_PTHREAD
+
 # Check for boost libraries used in estimation DLL
 AC_LANG_PUSH([C++])
 AX_BOOST_BASE([1.36], [], [AC_MSG_ERROR([Can't find Boost >= 1.36])])
-- 
GitLab