Technical Solutions
How do I debug a MEX-file using Xcode on MacOS X?
Date Last Modified: Friday, June 26, 2009
| Solution ID: | 1-22BGKF | |
| Product: | MATLAB | |
| Reported in Release: | R14SP3 | |
| Platform: | Mac | |
| Operating System: | Mac OS 10.4x (Tiger) |
Subject:
How do I debug a MEX-file using Xcode on MacOS X?
Problem Description:
I would like to debug a MEX-file using the Xcode development environment on a Macintosh.
Solution:This Solution is specific to the Apple Xcode debugger on Mac. For other configurations, see the Debugging section of Tech Note 1605, MEX-files Guide:
The following steps demonstrate how to debug a MEX-file in Xcode (version 2.0) for MacOS 10.4 (Tiger) and MATLAB 7.1 (R14SP3). 1. Open Xcode and select "File -> New Project..." 2. Choose to create a project of type "Dynamic Library -> BSD Dynamic Library". Name the project as you choose. In this example, the timestwo.c MEX-file included with MATLAB (located in $MATLAB/extern/examples/refbook/) will be used for demonstration, so the project is named timestwo. $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB Command Prompt.3. In the new project, highlight "Targets -> timestwo" in the Projects and Groups pane. Choose "File -> Get Info" or press Cmd-I to bring up the settings for this target. Modify the following options in the "Build" tab:
4. Select the "Rules" tab and select the GCC 3.3 compiler. 5. Highlight the project in the Projects and Groups pane, select "File -> Add Existing File...", and add the file $MATLAB/extern/src/mexversions.c to the list of project source files. 6. Add your C MEX-function file to the project. The timestwo.c file can be copied or added directly to the project. 7. At this point, you should be able to build your MEX-function. Press the build button and verify that the build is successful. Now you can use the MEX-function from within MATLAB. 8. To debug from within Xcode, you will need to create a custom executable that launches MATLAB from Xcode. Select "Project -> New Custom Executable". 9. Change the name of the new executable as desired, and set the location as: Please note that if you use the "Browse..." button and navigate to this directory, you will see two items named MATLAB; the one you should select is listed as a "Unix Executable". 10. Select the Arguments tab and set the following argument: You can also set any other desired MATLAB command-line options as arguments. Also set the following environment variables:
11. You should now be able to launch MATLAB by selecting "Debug -> Debug Executable". 12. Once MATLAB has launched, navigate to the directory where your build products are located (this may already be the current directory, depending on the settings you chose when creating the executable in Xcode). Add a breakpoint in your MEX-file and then run the MEX-function from the MATLAB prompt. It should stop on the breakpoint. You can now debug your MEX-function in Xcode as you would any other Xcode project. |
Related Solutions:
|
|
Store

