My project is in C++. I want to use matlab optimization nonlinsq
through matlab engine by "eval". I want to pass a function I wrote in C++ in the format of
void func(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
to matlab as a function handle without compiling it to mex.
I tried following Passing C/C++ callbacks into the matlab engine for creating a mxArray and then pass it to matlab workspace:
mxArray *fh = mclCreateSimpleFunctionHandle(func);
engPutVariable(engine, "func", fh);
mxDestroyArray(fh);
but the program crashed on the first line with access violation. In the call stack the last call before the violation was "mclmcrrt8_5.dll!000000000031dacd() Unknown"
What is the problem?..