How to debug generated mex codes
46 次查看(过去 30 天)
显示 更早的评论
I am trying to build an application in C++ using Visual Studio 2017. I have added paths in the directory as recommended https://www.youtube.com/watch?reload=9&v=vQ5aIxCX3To. Somehow I get an error - libmx.dll not found. I tried following - I copied this dll from bin\win64 and pasted it in the solution directory. After this I got error saying a different dll is missing. Then I tried to copy entire bin\win64 in a different location and added that path. Still the same error. Please help me resolve the issue.
When I generate mex from my code it works just fine, but I can't run the code in Visual Studio-17. Thanks
0 个评论
采纳的回答
Ryan Livingston
2018-10-26
Moved from comment To debug generated MEX code, just pass the -g option to codegen and that will compile a debug MEX file. You can then debug that MEX code by following the same process you'd use for debugging hand-written MEX files:
In short, you compile and run the MEX in MATLAB and attach Visual Studio to MATLAB, stopping when the MEX code is executed.
Note that the -g option is the same as the Coder config setting EnableDebugging:
1 个评论
Maya Jubran
2022-1-19
Hello
How to actually debug the mex file in the matlab coder . I have built the buildInstrumented mex file successfuly, and following the command line to run the mex file , the error returns to me. What is the full command to enable debugging the mex file ? THank you
更多回答(1 个)
Ryan Livingston
2018-10-23
It sounds like you are generating MEX code. MEX code assumes that MATLAB is present and as a result it may have a large number of dependencies. For this reason, MEX code should be compiled in MATLAB with MATLAB Coder or the MEX command. Compiling it with Visual Studio outside of MATLAB is not recommended.
Instead you can choose one of the standalone code generation options to use inside of Visual Studio. You can do that with:
cfg = coder.config('lib'); % or 'dll'
codegen -config cfg myFunction.m -args ...
and then use that code in Visual Studio. More info on generating standalone code:
Here's an example of using the generated code in Visual Studio:
Finally, the Deployment category in the documentation may be of interest:
3 个评论
Ryan Livingston
2018-10-24
编辑:Ryan Livingston
2018-10-24
Got it. That helps. Just pass the -g option to codegen and that will compile a debug MEX file. You can then debug that MEX code by following the same process you'd use for debugging hand-written MEX files:
In short, you compile and run the MEX in MATLAB and attach Visual Studio to MATLAB, stopping when the MEX code is executed.
Note that the -g option is the same as the Coder config setting EnableDebugging:
If that helps, would you consider changing the title of this question to something like "How do I debug MATLAB Coder MEX files?" so that others could find it?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Code Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!