How to manually edit MatLab Coder .mex-file code to support 64bit indexing

19 views (last 30 days)
I have a problem that mex files generated by MatLab Coder only supports 32bit indexing, which is the reason my program gets an error when the input of the bottleneck mex function exceeds an input boolean matrix which has more than 2^31 elements.
I know that mex-files support 64bit indexing when they are hand written, but since I am not comfortable with c or c++, I wonder if there is a way, and if so how, to manually correct this at the end of the coder when it shows me the code it generated?
I read that i shoukld have to replace the 'int32_T' by 'size_t' but thats not all, I would also need to replace the the constructors 'coder::array<T, 1U>' with C MEX API... and thats the point where my knowledge ends and I would need some help about what to do exactly and how to do it.
May be someone coukld help me with that.
Best regards and many thanks in advance

Answers (1)

Nitin Kapgate
Nitin Kapgate on 18 Dec 2020
Edited: Nitin Kapgate on 18 Dec 2020
So you will need to manually change the codein C/C++ files.
You can refer to the guide to enable support for 64-bit indexing in MEX files using compatibleArrayDims flag in mex command.
You can use these additional instructions to upgrade MEX files to use 64-Bit API.
gregory pais
gregory pais on 7 Jun 2022
Edited: gregory pais on 7 Jun 2022
mex compiler indicates you that functions emlrt are not found. To solve it you have to indicate to the linker where these functions are present. These functions are present in libemlrt.lib under matlabroot\extern\lib\mingw64. You have to add the library file to the mex command like this mex -v *.cpp '-llibemlrt'.
Probably you have to add libmwmathutil where muDouble functions like muDoubleScalarMin are defined.
mex -v *.cpp '-llibemlrt' '-llibmwmathutil'

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!