How do I debug a MATLAB 7.4 (R2007a) C/C++ MEX-file in Intel Visual C++ 9.1 using Microsoft Visual Studio 2005?

1 view (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
1. To debug a MEX-file from within MATLAB, you must first compile the MEX-file with the -g option to the mex function. The -g option builds the MEX-file with debugging symbols included. For example:
mex -g yprime.c
On a 32–bit platform, this command creates the executable file yprime.mexw32.
2. Start the Microsoft Visual Studio 2005 Development Environment. Do not exit your MATLAB session.
3. On the Visual Studio Tools menu, select Attach to Processes. In the Processes dialog box, select the MATLAB process and click Attach.
4. Open the source files by selecting File > Open > File. Set a breakpoint on the desired line of code by right-clicking the line of code and clicking Insert Breakpoint on the context menu. If you have not yet run the executable file, ignore any "?" that appears with the breakpoint next to the line of code.
5. In MATLAB, start the executable file, which runs in the Microsoft debugging environment:
yprime(1,1:4)
For more information on how to debug in the Microsoft environment, refer to the Microsoft Development Environment documentation.

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!