[英]Debug a mex function in Visual Studio
I'm trying to wrap existing C++ code into a MATLAB callable function. 我正在尝试将现有的C ++代码包装到MATLAB可调用函数中。 I'm using Visual Studio 2013 to generate the MEX file .
我正在使用Visual Studio 2013 生成MEX文件 。 The MEX file is created properly, I can call it from MATLAB and pass arguments back and forth without any issues.
MEX文件是正确创建的,我可以从MATLAB中调用它并来回传递参数而不会出现任何问题。
Now I want to debug my C++ logic, and I can't seem to get it to work. 现在我想调试我的C ++逻辑,我似乎无法让它工作。 I've created an m script that calls my function, and had Visual Studio run MATLAB when debugging - as explained here .
我创建了叫我的功能一个m脚本,在调试的时候有Visual Studio中运行MATLAB -作为解释在这里 。
When I hit F5 to debug my MEX file, Visual Studio runs MATLAB, and then exits debug mode very quickly, as if the MATLAB process terminated. 当我按F5调试我的MEX文件时,Visual Studio运行MATLAB,然后非常快地退出调试模式,就像MATLAB进程终止一样。 A few seconds after that , MATLAB starts running the code.
几秒钟后 ,MATLAB开始运行代码。 It is as if the MATLAB instance I'm running starts another instance and terminates, confusing Visual Studio.
就好像我正在运行的MATLAB实例启动另一个实例并终止,混淆了Visual Studio。
How can I debug my MEX function? 如何调试MEX功能?
UPDATE: Apparantly MATLAB is doing exactly that, as described here . UPDATE:Apparantly MATLAB的做法刚好,作为描述在这里 。 Adding the
-wait
argument makes Visual Studio wait until the script is done running, but the breakpoints I set don't work - because the process being debugged is not the process loading the DLL. 添加
-wait
参数使Visual Studio等到脚本运行完毕,但我设置的断点不起作用 - 因为正在调试的进程不是加载DLL的进程。
Turns out <MATLABROOT>\\bin\\matlab.exe
actually runs <MATLABROOT>\\bin\\w64\\matlab.exe
. 结果
<MATLABROOT>\\bin\\matlab.exe
实际运行<MATLABROOT>\\bin\\w64\\matlab.exe
。 So if I ask Visual Studio to run that, breakpoints are triggered as expected. 因此,如果我要求Visual Studio运行它,则会按预期触发断点。
Running MATLAB this way under the debugger is a lot slower than any other way, but at least now I can debug my code. 在调试器下以这种方式运行MATLAB比任何其他方式慢很多 ,但至少现在我可以调试我的代码。
You could also run a MATLAB session as usual, and then attach Visual Studio to the running process. 您也可以像往常一样运行MATLAB会话,然后将Visual Studio连接到正在运行的进程。 This is explained in more details in the documentation .
这在文档中有更详细的解释。 Here is a quick summary:
这是一个快速摘要:
matlab.exe
process. matlab.exe
进程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.