A Project template for creating Matlab mex files
Much of this came from the files at http://au.mathworks.com/matlabcentral/answers/125043-how-to-build-and-debug-matlab-mex-file-with-xcode-5-1-ide-on-os-x which don't work with Xcode 6 (they cause Xcode to crash) my work simplifies the process and the location for install specified at the above link is not correct and will be overwritten at every update of XCode better to install as shown below.
I have also added the files for a hello world application.
-
mkdir -p $HOME/Library/Developer/Xcode/
-
Then put the folder Templates from the git respository into $HOME/Library/Developer/Xcode/
-
Open Xcode 6 and select 'File -> New -> Project' In the left column choose Templates and then select MEX.
-
The 'Product Name' should be the same as the name of the MEX-function you wish to create.
-
Enter the name of the MATLAB application as it appears in finder the default is 'MATLAB_2015a'. This is used to create paths to the library and header files contained within the Matlab application bundle.
-
Choose a location for you mex project.
-
You now have a project with a function that prints hello world. You can build it by selecting 'Product-> Build For-> Testing.
NOTE if this fails it is probably because the configuration in the generated .xcconfig has not been selected you can do this by using the 'Project Navigator' to look at the 'info' page for the project then by selecting the only configuration available for both debug and release builds. I hope to work out how to make the template set these two values automatically soon.
- You debug by attaching to a running instance of Matlab by selecting 'Debug->Attach to Process->Matlab'
- Set a breakpoint in the Hello World source code somewhere (by clicking on the line number at the line you want to set the breakpoint at), set Matlabs path to point to the folder where the newly built mex file is and then type the name of the mex function in Matlab. The debugger should come up when you hit the breakpoint set in the source code.