在Visual Studio中调试一个mex函数 [英] Debug a mex function in Visual Studio
问题描述
现在我想调试我的C ++逻辑,我可以似乎让它上班。我创建了一个调用我的函数的m脚本,Visual Studio在调试时运行MATLAB,如此处所述。 / p>
当我点击F5调试我的MEX文件时,Visual Studio运行MATLAB,然后很快退出调试模式,就像MATLAB进程终止一样。之后的几秒钟,MATLAB开始运行代码。就像我正在运行的MATLAB实例启动另一个实例并终止,混淆了Visual Studio。
如何调试MEX功能?
更新:Apparantly MATLAB正在做,正如这里。添加 -wait
参数使Visual Studio等待脚本运行完毕,但我设置的断点不起作用 - 因为正在调试的进程不是加载DLL。
得出< MATLABROOT> \bin\matlab.exe
实际运行< MATLABROOT> \bin\w64\matlab.exe
。所以如果我要求Visual Studio运行它,那么断点将按预期触发。
在调试器下运行MATLAB这个方法比很多慢很多任何其他方式,但至少现在我可以调试我的代码。
I'm trying to wrap existing C++ code into a MATLAB callable function. I'm using Visual Studio 2013 to generate the MEX file . The MEX file is created properly, I can call it from MATLAB and pass arguments back and forth without any issues.
Now I want to debug my C++ logic, and I can't seem to get it to work. I've created an m script that calls my function, and had Visual Studio run MATLAB when debugging - as explained here .
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. A few seconds after that, MATLAB starts running the code. It is as if the MATLAB instance I'm running starts another instance and terminates, confusing Visual Studio.
How can I debug my MEX function?
UPDATE: Apparantly MATLAB is doing exactly that, as described here. 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.
Turns out <MATLABROOT>\bin\matlab.exe
actually runs <MATLABROOT>\bin\w64\matlab.exe
. So if I ask Visual Studio to run that, breakpoints are triggered as expected.
Running MATLAB this way under the debugger is a lot slower than any other way, but at least now I can debug my code.
这篇关于在Visual Studio中调试一个mex函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!