From d00dd514bdfc89d6c8bb2b01d7ba03492eb7a208 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Thu, 26 Aug 2010 17:26:44 +0200
Subject: [PATCH] Build system: fix bug for compilation with mingw 64-bit
 (linking with MSVC export files creates MEX files which crash, while directly
 linking with the DLL binary works) (cherry picked from commit
 424b299e0759659e8dbe95de3c8fe8e3813487d1)

---
 m4/ax_mexopts.m4 | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/m4/ax_mexopts.m4 b/m4/ax_mexopts.m4
index e52c36b5bc..ac41fa5bde 100644
--- a/m4/ax_mexopts.m4
+++ b/m4/ax_mexopts.m4
@@ -50,23 +50,13 @@ case ${MATLAB_ARCH} in
   win32 | win64)
     MATLAB_CFLAGS="-fexceptions -g -O2"
     MATLAB_CXXFLAGS="-g -O2"
-    case $MATLAB_VERSION in
-      6.5*|7.0|7.0.0|7.0.4)
-        LIBLOC="$MATLAB/extern/lib/${MATLAB_ARCH}/microsoft/msvc60"
-        ;;
-      7.0.1)
-        AC_MSG_ERROR([MATLAB version 7.0.1 (R14SP1) is buggy (LAPACK library missing for MSVC), and can't be used for compiling MEX files])
-        ;;
-      *)
-        LIBLOC="$MATLAB/extern/lib/${MATLAB_ARCH}/microsoft"
-        ;;
-    esac
+    AX_COMPARE_VERSION([$MATLAB_VERSION], [eq], [7.0.1], [AC_MSG_ERROR([MATLAB version 7.0.1 (R14SP1) is buggy (LAPACK library missing for MSVC), and can't be used for compiling MEX files])])
     MATLAB_DEFS="$MATLAB_DEFS -DNDEBUG"
     # Note that static-libstdc++ is only supported since GCC 4.5 (but generates no error on older versions)
-    MATLAB_LDFLAGS="-static-libgcc -static-libstdc++ -shared \$(top_srcdir)/mex.def"
-    MATLAB_LIBS="$LIBLOC/libmex.lib $LIBLOC/libmx.lib $LIBLOC/libmwlapack.lib"
+    MATLAB_LDFLAGS="-static-libgcc -static-libstdc++ -shared \$(top_srcdir)/mex.def -L$MATLAB/bin/${MATLAB_ARCH}"
+    MATLAB_LIBS="-lmex -lmx -lmwlapack"
     # Starting from MATLAB 7.5, BLAS and LAPACK are in distinct libraries
-    AX_COMPARE_VERSION([$MATLAB_VERSION], [ge], [7.5], [MATLAB_LIBS="${MATLAB_LIBS} $LIBLOC/libmwblas.lib"])
+    AX_COMPARE_VERSION([$MATLAB_VERSION], [ge], [7.5], [MATLAB_LIBS="${MATLAB_LIBS} -lmwblas"])
     ax_mexopts_ok="yes"
     ;;
   maci | maci64)
-- 
GitLab