debugging matlab mex
- 1 minutes read - 90 wordsOne thing I’ve been doing a bit of lately is debugging MATLAB mex files; it seemed worth documenting. The broad strokes:
- recompile all mex codes with ‘-g’
- quit MATLAB
- From a command prompt, run
$ /Applications/MATLAB_R2012a.app/bin/matlab -Dgdb
[snip]
(gdb) run -nojvm
>> run_your_mex_file
This gives debugging output. If there is an error in the code, you’re dropped back to a gdb prompt, where you can continue debugging in a semi-normal fashion. Typically, I end up doing a ‘where’ to get a stack trace, and debug from there more-or-less like usual.