How do *you* debug mex files on Mac OS

조회 수: 2(최근 30일)
Oliver Woodford
Oliver Woodford 2015년 10월 22일
답변: Oliver Woodford 2016년 11월 15일
I'm having trouble debugging on a Mac for the first time. I'd like to know how you do it.


Rahul Goel
Rahul Goel 2015년 10월 26일
Hi Oliver, you can follow the steps below to debug your MEX-file using Xcode 4.3, Xcode 4.4 or Xcode 4.5 on OS X 10.7 (Lion) or OS X 10.8 (Mountain Lion) :
1. Download (the Xcode MEX-Library project template) and put it into: Applications/<Xcode>/Developer/Library/Xcode where Xcode is the folder for the specific version of Xcode you are using.
make sure you follow the folder structure as shown below.
You do not need to quit Xcode for it to recognize the template.
2. Open Xcode and select "File --> New --> Project..."
3. On the left column, choose the category MathWorks and select type MEX-Library.
4. Name the "Product Name" after your MEX-function (e.g. timestable, the example located in $MATLAB/extern/examples/refbook).
5. Enter the name of your MATLAB application as it appears in finder, e.g. MATLAB_R2012b.
6. Add your MEX-function file(s) into the project hierarchy (e.g., drag and drop), making sure to check 'Copy items into destination group's folder' so that the file(s) will be copied into your project directory and also make sure the target checkbox is checked.
7. In XCode select your project and go to its "Build Settings". Make sure that you are in the "All" view (instead of "Basic") and then look for the "Optimization Level" setting; this setting should be set to "None". If the Optimization Level is set to anything else than None, it is not guaranteed that your code is executed in the order that it has been written which would make efficient debugging virtually impossible.
8. At this point, everything has been setup for you, so hit Cmd-B to build your MEX-function and verify that the build is successful. Now you can use the MEX-function from within MATLAB.
9. To debug from within Xcode, launch MATLAB as you normally would and attach to the MATLAB process from within Xcode.
10. In MATLAB, cd to the place where the Xcode product was built, i.e.
cd $(YOUR_XCODE_PROJECT_DIR)/build/Debug
(the product is placed in the subdirectory build/$(CONFIGURATION) of the project root).
11. Add a breakpoint in your MEX-file and then run the MEX-function from the MATLAB prompt. The control should stop at the break-point in Xcode.
Hope this helps.
  댓글 수: 1
Oliver Woodford
Oliver Woodford 2015년 10월 27일
Thanks, Rahul. Where would I find

댓글을 달려면 로그인하십시오.

Oliver Woodford
Oliver Woodford 2016년 11월 15일
This is how I do it.


Find more on Introduction to Installation and Licensing in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by