matlab调试C

本文介绍了如何使用Microsoft Visual Studio 2005调试MATLAB编译的MEX文件。首先,通过'mex -setup'选择Visual C++ 2005编译器,然后使用'-g'选项编译源代码。接着,在Visual Studio中附加到MATLAB进程,打开源文件并设置断点。在断点处,可以利用调试器检查变量和内存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

The Microsoft® Visual Studio® development environment provides complete source code debugging, including the ability to set breakpoints, examine variables, and step through the source code line-by-line.

For information on debugging MEX-files compiled with other MATLAB supported compilers, see Debugging on Windows in Technical Note 1605, MEX-files Guide.

Visual Studio 2005

This section describes how to debug using the default compiler, that is, the compiler used to build MATLAB.

  1. Select the Microsoft Visual C++ 2005 compiler. At the MATLAB prompt, type:

    mex -setup

    Type y to locate installed compilers, and then type the number corresponding to this compiler.

  2. Next, compile the source MEX-file with the -g option, which builds the 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 Visual Studio®. Do not exit your MATLAB session.

  4. From the Visual Studio Tools menu, select Attach to Process...[]

     

  5. In the Attach to Process dialog box, select the MATLAB process and click Attach.

    Visual Studio loads data then displays an empty code pane.

  6. Open the source file yprime.c by selecting File > Open > Fileyprime.c is found in the matlabroot/extern/examples/mex/ folder.

  7. Set a breakpoint by right-clicking the desired line of code and following Breakpoint > Insert Breakpoint on the context menu. It is often convenient to set a breakpoint atmexFunction to stop at the beginning of the gateway routine.

    If you have not yet run the executable file, ignore any "!" icon that appears with the breakpoint next to the line of code.

    Once you hit one of your breakpoints, you can make full use of any commands the debugger provides to examine variables, display memory, or inspect registers.

  8. Run the binary MEX-file in MATLAB. After typing:

    yprime(1,1:4)

    yprime.c is opened in the Visual Studio debugger at the first breakpoint.

  9. If you select Debug > Continue, MATLAB displays:

    ans =
    
        2.0000    8.9685    4.0000   -1.0947
    

    For more information on how to debug in the Visual Studio environment, see your Microsoft documentation.

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值