How do I debug my MEX-files using Xcode 4.3+ on OS X?

2 views (last 30 days)
I have a MEX-file that I want to debug using Xcode 4.5 and would like to know how to do this on OS X 10.7 (Lion) or OS X 10.8 (Mountain Lion).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2013
Please follow the steps below to debug your MEX-file using Xcode 4.3, Xcode 4.4 or Xcode 4.5:
1. Download Templates.zip (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 breakpoint in Xcode.

More Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!