Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How do I debug a MEX-file in Microsoft Visual C++ .NET 2003?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-1BUHC
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I debug a MEX-file in Microsoft Visual C++ .NET 2003?

Problem Description:

I would like to debug a MEX-file in Microsoft Visual C++ .NET.

Solution:

This Solution is specific to the Microsoft Visual Studio .NET 2003 debugger on Windows. For other configurations, see the Debugging section of Tech Note 1605, MEX-files Guide:
http://www.mathworks.com/support/tech-notes/1600/1605.html


NOTE: This solution is not officially supported by The MathWorks.
The following steps demonstrate how to debug a MEX-file in the Microsoft Visual C++ .NET environment:

1. Open the Visual Studio .NET development environment.
2. Open a New "empty" project.
3. Select File->Add Existing Item... And select the name of the MEX-file DLL.
4. Select File->Add Existing Item... And select the name of the MEX-file source.
5. Open the MEX-file source by double-clicking on it in the Solution Explorer frame.
6. Place a break point at the appropriate line of code.
7. Select Project->$PROJECT_NAME settings where $PROJECT_NAME is the name of your project.
8. Under the Configuration Properties, click on "Debugging."
9. Click on "Command" under Action and browse to the MATLAB executable file $MATLABROOT/bin/win32/matlab.exe where $MATLABROOT is the directory in which MATLAB is installed.
10. Click OK.
11. Select Debug->Start or press F5.
12. Click NO if it prompts you to rebuild the out of date project.
13. Click "OK" if it reports that matlab.exe does not contain debugging symbols.

This should open the MATLAB environment after a few moments.

14. Change to the directory location of the MEX-file using the CD command in MATLAB
15. Execute the MEX-file normally. This will start the MSVS 7.0 environment and stop at the break point.

You should now be able to step through the MEX-file as you would any C/C++ applicaton.

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page