How do *you* debug mex files on Mac OS

4 ビュー (過去 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.

回答 (2 件)

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.


Community Treasure Hunt

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

Start Hunting!

Translated by