MEX, Mingw and linking libraries

I'm trying to compile some code under win7 64bit with MATLAB which compiles well under Linux. For this I use MEX with Mingw and gcc compiler.
My original Linux MEX command was looking like this
mex CFLAGS="\$CFLAGS -Wall -fomit-frame-pointer -m32 -msse2 -mfpmath=sse -ffast-math" -lmwblas -lmwlapack -lmx -lmex -lmat -lm hkmeans_predict_dense.cpp
so I converted it to link a libraries from MATLAB directory
mex -f mingw.bat -L"C:\Program Files\MATLAB\MATLAB Production Server\R2015a\extern\lib\win64\microsoft\" CFLAGS="\$CFLAGS -Wall -fomit-frame-pointer -m32 -msse2 -mfpmath=sse -ffast-math" -lmwblas -lmwlapack -lmx -lmex -lmat hkmeans_predict_dense.cpp
I don't get any error about missing library but I'm getting undefined reference to `dgemm_' which points to some missing lapack function.
So my question is:
1) Was it OK to link libraries from MATLAB win64\microsoft\ directory but using gcc compiler ?? Are they compatibile with gcc ??
2) if not from where I can get such prebuild libraries for gcc under windows ??
Krzysztof

4 Comments

Walter Roberson
Walter Roberson on 14 Jan 2016
Edited: Walter Roberson on 14 Jan 2016
Notice the #define used in http://uk.mathworks.com/matlabcentral/answers/252395-calling-lapack-in-mex-files . The reverse of it would be that if you have coded in terms of dgemm_ then on Windows you would need to #define that in terms of dgemm
#define dgemm_ dgemm and using g++ fixed the compiling problem but unfortunately compiled mex is not running. So question remains: Are those libraries OK ??
Sorry, I do not know.
Hello Krzysztof,
You should not be linking against the libraries in $matlabroot\extern\lib\win64\microsoft folder when using MinGW Compiler. Instead you should link against the libraries in the folder $matlabroot\extern\lib\win64\mingw64 when using MinGW Compiler.
Hope this helps.

Sign in to comment.

Answers (2)

Guan claim
Guan claim on 25 Apr 2016
Sorry~ I don't understand that what library it is to contain these orders. is it the blas library?
timo
timo on 28 Mar 2018
I think MSVC and MinGW operate differently w.r.t. expected extensions. While MSVC normally creates static libraries with a .lib extension, MinGW/MSYS respects the Unix defaults and requires a .a

Asked:

on 14 Jan 2016

Answered:

on 28 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!