问题
I don't have experience with C/C++ syntax and I am facing the issue of adjusting this change of syntax. I am trying to generate the mex file for libvisio2. I have visual studio 2017 and matlab 2018a.
the complete error is
D:\Libraries\libviso2\matlab\matcherMex.cpp(101): error C2440: 'initializing': cannot convert from 'const mwSize *' to
'const int32_t *'
D:\Libraries\libviso2\matlab\matcherMex.cpp(101): note: Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
where the lines in the file matcherMex.cpp are:
99: // get pointer to left image
100: uint8_t* I1 = (uint8_t*)mxGetPr(prhs[1]);
101: const int32_t *dims1 = mxGetDimensions(prhs[1]);
102:
103: // transpose
104: uint8_t* I1_ = transpose<uint8_t>(I1,dims1);
105: int32_t dims1_[] = {dims1[1],dims1[0],dims1[1]};
Any help would be appreciated , Thanks
回答1:
When compiling, you need to pass the -compatibleArrayDims to the mex
function.
By default, MEX-files are compiled in a mode where array indices and sizes are stored in 64-bit integers (this is how MATLAB stores them natively). Back in the old days, presumably when your code was written, they were 32-bit integers. The given compiler flag will make MATLAB automatically convert the types of these variables for you (and hopefully throw an error if the array size is too large to fit in a 32-bit integer).
来源:https://stackoverflow.com/questions/53350219/mex-compilation-error-c2440-initializing-cannot-convert-from-const-mwsize