Error using mex : In function 'void mexFunction(int, mxArray**, int, const mxArray**)'
Show older comments
In my mecherMex.cpp, I wright down "void mexFunction (int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) {", but I dont know why system says my function is 'void mexFunction(int, mxArray**, int, const mxArray**)'. Does any one has same problem?
Answers (1)
James Tursa
on 8 Jun 2020
Edited: James Tursa
on 8 Jun 2020
The error is not with mexFunction. The error is with line in your source code:
const int32_t *dims1 = mxGetDimensions(prhs[1]);
which needs to be this instead:
const mwSize *dims1 = mxGetDimensions(prhs[1]);
To answer your question as to why you write this signature:
void mexFunction (int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
but the compiler says the signature is this:
void mexFunction(int, mxArray**, int, const mxArray**)
you have to remember that C/C++ does not pass arrays in argument lists. The square brackets [ ] that look like arrays are in fact interpreted by the compiler as "pointer to" when they appear in argument lists. So this
mxArray *plhs[ ]
in an argument list does not mean "array of pointers to mxArray"
It does mean "pointer to pointer to mxArray", i.e. the [ ] simply gets replaced with "pointer to".
2 Comments
CHENGXIAN KI
on 10 Jun 2020
James Tursa
on 10 Jun 2020
Looks to me like you still have mwSize vs int32_t mismatches in your code. You need to fix those up.
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!