How do I debug a MATLAB C/C++ MEX-file in Microsoft Visual Studio 2005?
20 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2012 年 9 月 10 日
編集済み: MathWorks Support Team
2020 年 8 月 12 日
I would like to debug a C or C++ MEX-file in Microsoft Visual Studio 2005.
採用された回答
MathWorks Support Team
2020 年 8 月 12 日
編集済み: 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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call C++ from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!