MATLAB: MinGw64 compiler bugged in 2018a

MATLABmingw

I try to build a mex of a file who used lib c:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\x86_64-w64-mingw32\lib\libiphlpapi.a
When i use the mex command it looks for .lib files. But all the libraries are .a in the folder which i specified with -L . How to make linker to look for .a files ?
Here is the command:
mex -v -L"c:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\x86_64-w64-mingw32\lib" -llibiphlpapi.a MACAddress_mex.c
Verbose mode is on.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
Set PATH = C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\bin;C:\MATLAB\R2018a\extern\include\win64;C:\MATLAB\R2018a\extern\include;C:\MATLAB\R2018a\simulink\include;C:\MATLAB\R2018a\lib\win64;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;C:\TDM-GCC-64\bin;C:\MATLAB\R2018a\bin;C:\Users\timo\AppData\Local\Microsoft\WindowsApps;c:\SysGCC\mingw64\bin;
Set INCLUDE = C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\include;;C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\include;;
Set LIB = C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\lib;;C:\ProgramData\MATLAB\SupportPackages\R2018a_1\3P.instrset\mingw_w64.instrset\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\MATLAB\R2018a\extern\lib\win64;C:\MATLAB\R2018a\extern\lib\win64;
Error using mex
MEX cannot find library 'libiphlpapi.a' specified with the -l option.
MEX looks for a file with one of the names:
liblibiphlpapi.a.lib
libiphlpapi.a.lib
Please specify the path to this library with the -L option.
Ps: it worked if i renamed the libiphlpapi.a to libiphlpapi.lib , but seems like a hack and not a proper solution . 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

Best Answer

  • Correction : The user have to give the path to the MinGW64 lib .a file even if its in the MinGW64 standard lib directory . Thats very user unfriendly and i reported this mex behaviour to the mingw64 developers
    Here is the correct command (please note that for VS2017 compiler only -l libname is enough !)
    mex -v c:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset\x86_64-w64-mingw32\lib\libiphlpapi.a MACAddress_mex.c