How do I debug a MATLAB C/C++ MEX-file in Microsoft Visual Studio 2005?

19 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2020-8-12
This Solution is specific to the Microsoft Visual Studio 2005 debugger on Windows, and works on MATLAB 7.3 (R2006b) or later. Note that this process will not work if you only have Visual C++ installed (and not Visual Studio).
1. To debug a C/C++ MEX-file from the Microsoft Visual Studio 2005, you must first choose the Microsoft Visual C/C++ version 8.0 compiler in MATLAB, using the command:
mex -setup
2. Compile the MEX-file with the -g option, which 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.
3. Start the Microsoft Visual Studio 2005 Development Environment. Do not exit your MATLAB session.
4. In Microsoft Development Environment, select Tools->Attach to Process... from the menu bar.
5. In the Processes dialog box, select the MATLAB process and click Attach.
6. 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 selecting Breakpoint ->Insert Breakpoint from 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.
7. 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.
A more specific writeup of the above procedure, along with instructions on how to debug with gdb on Linux, is available in the MATLAB documentation here:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call C++ from MATLAB 的更多信息

产品


版本

R2006b

Community Treasure Hunt

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

Start Hunting!

Translated by