From: Patrick Grosa on
Hello,

I know, that this a very special problem and I would like to provide an error log or something like this, but this is the problem.

Following situation:
Matlab 2010a (64bit) on Win 7 64bit Enterprise
Mingw-w64 with basis msys environment
used modified gnumex to create .def and .lib files
mexopt.bat modified to work with mingw

This setup works perfectly. I can write,compile,link and run mex files.
Moreover, I compiled the itpp library with msys/mingw and created static libs as well as shared libs.

Now, the problem:
At the point, when I include an itpp related class of function in the mex file, I can compile and link the mex-file without errors or warnings (except for some ignore statements,'cause of duplicated pathes).

However, when I run the mexfile matlab crashes without messages, logs or dumps. I also used try...catch..., but same behavior.

Well, has anybody an idea how i can debug this? Stepping through the call stack or something like this without logs? Or is there a way to force matlab to go through the steps?

Any ideas?

Very thanks in advance.

Best regards,
Patrick
From: Cris Luengo on
"Patrick Grosa" <blubb(a)nolimitmail.com> wrote in message <i24bi4$q8m$1(a)fred.mathworks.com>...
> Hello,
>
> I know, that this a very special problem and I would like to provide an error log or something like this, but this is the problem.
>
> Following situation:
> Matlab 2010a (64bit) on Win 7 64bit Enterprise
> Mingw-w64 with basis msys environment
> used modified gnumex to create .def and .lib files
> mexopt.bat modified to work with mingw
>
> This setup works perfectly. I can write,compile,link and run mex files.
> Moreover, I compiled the itpp library with msys/mingw and created static libs as well as shared libs.
>
> Now, the problem:
> At the point, when I include an itpp related class of function in the mex file, I can compile and link the mex-file without errors or warnings (except for some ignore statements,'cause of duplicated pathes).
>
> However, when I run the mexfile matlab crashes without messages, logs or dumps. I also used try...catch..., but same behavior.
>
> Well, has anybody an idea how i can debug this? Stepping through the call stack or something like this without logs? Or is there a way to force matlab to go through the steps?
>
> Any ideas?
>
> Very thanks in advance.
>
> Best regards,
> Patrick

Debugging MEX-files is difficult, but you can run MATLAB from your debugger, and set your debugger to only step through the code within the MEX-file. There used to be a section in the MATLAB manuals on this, I'm sure it's still there somewhere... :)

The alternative is to write a very simple command-line utility that executes you code. These are usually a lot easier to run in the debugger than the whole of MATLAB.

The thing I would start with: make a very simple MEX-file that links with the library and calls a very simple function in that library. Something you know should never SEGV. If this MEX-file doesn't work, you have a linking problem. If the library is linked dynamically, is it available on the PATH within MATLAB? Try the dependency walker to check you MEX-file for linked libraries and such: http://www.dependencywalker.com/

Good luck!
Cris.
From: Patrick on
Hello Chris,

Thank you for the advise. I realized that mex files are a very tricky thing.

I used eclipse and the gnu-debugger to attach to matlab and set a breakpoint at the very first beginning of this short main function:

#include <iostream>
#include <string>
#include <itpp/itmex.h>
//#include "mex.h"
using namespace std;

void mexFunction(int n_output, mxArray *output[], int n_input, const mxArray *input[])
{
itpp::vec b;//=itpp::linspace(10,10,20);
int a=10;
a=a+2;// Check the number of inputs and output arguments
if(n_output!=0) mexErrMsgTxt("Wrong number of output variables!");
if(n_input!=0) mexErrMsgTxt("Wrong number of input variables!");
mexErrMsgTxt("Super3");
return;
}

But the program never comes to this point, matlab crashes before. Well if i comment out the line "itpp::vec b;" everything works fine.

I also assumed a dependency problem and used the dependency walker at first called by double-click and then navigating to the file and afterwards, called from within matlab by a system('....') call in order to see the same pathes as matlab. And everything seems fine...

But one thing that I'm thinking about is the dependency of the itpp library on the blas, lapack and fftw3 library. I compiled them on my own and linked them to the itpp library. However, I didn't used the libs shipped with matlab.

Does you or anybody else if these links are automatically loaded by matlab by default? Maybe, this could produce the crash?

Thanks a lot again,
discussing the possibilities help a lot to find a solution

best regards,
Patrick


"Cris Luengo" <cris.luengo(a)google.for.my.name.to.contact.me> wrote in message <i24dac$n79$1(a)fred.mathworks.com>...
> "Patrick Grosa" <blubb(a)nolimitmail.com> wrote in message <i24bi4$q8m$1(a)fred.mathworks.com>...
> > Hello,
> >
> > I know, that this a very special problem and I would like to provide an error log or something like this, but this is the problem.
> >
> > Following situation:
> > Matlab 2010a (64bit) on Win 7 64bit Enterprise
> > Mingw-w64 with basis msys environment
> > used modified gnumex to create .def and .lib files
> > mexopt.bat modified to work with mingw
> >
> > This setup works perfectly. I can write,compile,link and run mex files.
> > Moreover, I compiled the itpp library with msys/mingw and created static libs as well as shared libs.
> >
> > Now, the problem:
> > At the point, when I include an itpp related class of function in the mex file, I can compile and link the mex-file without errors or warnings (except for some ignore statements,'cause of duplicated pathes).
> >
> > However, when I run the mexfile matlab crashes without messages, logs or dumps. I also used try...catch..., but same behavior.
> >
> > Well, has anybody an idea how i can debug this? Stepping through the call stack or something like this without logs? Or is there a way to force matlab to go through the steps?
> >
> > Any ideas?
> >
> > Very thanks in advance.
> >
> > Best regards,
> > Patrick
>
> Debugging MEX-files is difficult, but you can run MATLAB from your debugger, and set your debugger to only step through the code within the MEX-file. There used to be a section in the MATLAB manuals on this, I'm sure it's still there somewhere... :)
>
> The alternative is to write a very simple command-line utility that executes you code. These are usually a lot easier to run in the debugger than the whole of MATLAB.
>
> The thing I would start with: make a very simple MEX-file that links with the library and calls a very simple function in that library. Something you know should never SEGV. If this MEX-file doesn't work, you have a linking problem. If the library is linked dynamically, is it available on the PATH within MATLAB? Try the dependency walker to check you MEX-file for linked libraries and such: http://www.dependencywalker.com/
>
> Good luck!
> Cris.