MATLAB: MinGW not work as expected

mingw

I download minGW form https://github.com/mathworks/MinGW_53 and configure it with matlab the output of mex -setup
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
if true
% code
end
But when I test it at a previous code(.cpp) which is correctly compiled I received the error
In function 'void mexFunction(int, mxArray**,
int, const mxArray**)':
C:\Users\User\Desktop\t\private\edgesDetectMex.cpp:99:63: error: cannot convert 'const int*' to
'const mwSize* {aka const long long unsigned int*}' for argument '2' to 'mxArray*
mxCreateNumericArray_730(mwSize, const mwSize*, mxClassID, mxComplexity)'
pl[0] = mxCreateNumericArray(3,outDims,mxSINGLE_CLASS,mxREAL);
If I correctly configured minGW or not? and if not what is the wrong?

Best Answer

The error message is clear: The 2nd argument of mxCreateNumericArray is expected to be a mwSize*, but it is a int* in your code. So adjust the type of outDims accordingly.

The code might work correctly with another compiler, but remember, that the definition of int depends on the platform and the compiler. Therefore the Mex interface uses e.g. mwSize for many years now and should be used to avoid such incompatibilities.

 Why minGW not work as expected?

It seems like MinGW works as expected. This is just a bug in the code.