It is possible to compile a MEX file with "-g" and debug it on a different machine, although it is not guaranteed to work for every MEX file and debugger. For example, the following workflow was accomplished on Windows 10, MATLAB R2019b, and VS Code:
1) Use MATLAB to compile a MEX file with the "-g" flag:
>> mex -g sourceCode.c
2) Open the source code in Visual Studio Code and step through it with the gdb debugger after MATLAB calls the MEX function. To set up VS code debugging, use this tutorial from the MathWorks blog:
https://blogs.mathworks.com/developer/2018/06/19/mex-debugging-vscode/
Note that this tutorial requires you to install the "MATLAB Support for MinGW-w64 C/C++ Compiler" support package.
3) Transfer the source code and the compiled MEX file to a different computer with the same operating system and place both files in a folder with the same name and path as on the first computer.
4) Without recompiling the MEX file, open the source code in VS Code and step through it after MATLAB calls the MEX function.
Best Answer