feelfree
feelfree

Reputation: 11753

how to debug MATLAB .mex32/.mex64 files with Visual Studio 2010

I have a question related to debugging .mex32/.mex64 files. Suppose now I have a file named test.cpp:

#include "mex.h" 
#include <iostream>
void mexFunction(int nlhs, mxArray *plhs[],
    int nrhs, const mxArray *prhs[])
{
    mexPrintf("Hello Matlab, and this is a test program\n"); 
} 

I can then compile and build test.mex64 with Visual Studio 2010.Then in matlab, I can write the following script to test the function:

clc; 
test;

Now suppose I want to debug the test.mex64 function, what should I do? The have adopted the following procedure, but failed:

  1. Toggle break point at the begging of the line mexPrintfwith VS2010.
  2. With VS2010 from Debug->Attach to Process... select MATLAB.exe.
  3. Run MATLAB script clc; test;

The error message I have obtained is as follows:

The breakpoint will not currently be hit. No symbols have been loaded for this document. 

Upvotes: 2

Views: 4190

Answers (2)

feelfree
feelfree

Reputation: 11753

I have found the solution: when I created the .mexw64 function (test.mexw64 in our case), I copied it to the MATLAB work directory. In order to debug this function, it is important to copy test.pdb file to the MATLAB work directory as well. After doing that, I can debug.

Upvotes: 1

Navan
Navan

Reputation: 4477

Did you build your mex file with debug option "-g"?

Upvotes: 1

Related Questions