MATLAB Answers

How can I build an Engine application using the Xcode IDE on Mac?

13 views (last 30 days)
I would like to build an Engine application such as ENGDEMO.C on a Mac using the Xcode IDE instead of the MEX script in MATLAB.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Jun 2018
These instructions are written for Engine applications on Intel Macs running 32-bit MATLAB. For PowerPC Macs, substitute 'mac' for 'maci' in each of the paths listed below, while for 64-bit Intel Macs, substitute 'maci64' for 'maci'.
First, ensure that you are using a supported version of Xcode and gcc for your version of MATLAB:
1. Get the Unix shell PATH variable. Add ".", "$MATLABROOT/bin" and "$MATLABROOT/bin/maci".
where $MATLABROOT is your MATLAB installation directory, as returned by executing:
matlabroot
at the MATLAB Command Prompt.
2. Create new project, Command Line Utility: Standard Tool, with project name 'projname'. Select C/C++ Style not the default Foundation.
3. Add engdemo.c as main file.
4. Project -> Edit Project Settings, choose Build tab, select Search Paths group.
5. Select Architecture as x86 (32 bit Universal).
6. Header Search Path: Add
$MATLABROOT/extern/include
This search path setting corresponds to the "-I$MATLABROOT/extern/include" flags passed to gcc.
7. Select "Library search path" and click Edit. Click + and add "$MATLABROOT/bin/maci" and "$MATLABROOT/runtime/maci". Leave the existing "$(inherited)" item.
This setting corresponds to the "-L$MATLABROOT/bin/maci" flag passed to gcc.
8. Select the Preprocessing section, and set Preprocessor Macros to "MATLAB_MEX_FILE MX_COMPAT_32 NDEBUG".
This corresponds to the "-DMATLAB_MEX_FILE -DMX_COMPAT_32 -DNDEBUG" flags passed to gcc.
9. Switch to "Code Generation" group and select "No Common Blocks".
This corresponds to "-fno-common".
10. Set Optimization Level to "Fastest [-O3]".
This corresponds to "-O3".
11. Select "Language" group and ensure that "Enable C++ Exceptions" is checked.
This corresponds to "-fexceptions".
12. Switch to "Linking" group. Set "Other Linker Flags" to "-Wl,-flat_namespace -undefined suppress, -lmx and -leng".
13. In Project window, select Targets -> projname -> Link Binary with Libraries, control-click and select Add, and pick these libraries:
$MATLABROOT/bin/maci/libeng.dylib
$MATLABROOT/bin/maci/libmx.dylib
Ensure that "Copy files..." is not checked. This corresponds to the "-leng -lmx" flags passed to gcc.
14. Select Project->Edit Active Executable 'projname'. Switch to Arguments tab.
15. Add Unix shell PATH variable with value from step 1.
16. Add Unix shell DYLD_LIBRARY_PATH variable with the following values:
$MATLABROOT/runtime/maci:
$MATLABROOT/bin/maci:
$MATLABROOT/sys/os/maci:
/System/Library/Frameworks/JavaVM.framework/JavaVM:
/System/Library/Frameworks/JavaVM.framework/Libraries
Also, add variable XAPPLRESDIR with value:
$MATLABROOT/X11/app-defaults
This corresponds to the environment variables needed for Engine applications.
17. In Source window, click Build.
18. In Source window, click Build & Run. You should now be executing an Engine application within Xcode.

  2 Comments

Shin Chen
Shin Chen on 24 Nov 2015
Hi I'm very new to this forum. What's the meaning of "Add Unix shell PATH"? how to do that?
Richa Gupta
Richa Gupta on 30 Mar 2016
When you type any command on command prompt, the shell has to locate the command before it can be executed. The PATH variable specifies the locations in which the shell should look for commands. To find out what your path is, at the Unix shell prompt, enter:
echo $PATH
The syntax for setting path under Unix is dependent upon your login shell. If you are using tcsh or csh, shell:
setenv PATH $PATH:/path/to/dir1
If you are using bash, sh, or ksh:
export PATH=$PATH:/path/to/dir1

Sign in to comment.

More Answers (1)

Janos Buttgereit
Janos Buttgereit on 24 Oct 2016
I'm no Apple Developer, so I only have access to the latest Xcode Version - Xcode 8 in my case. I'm using Matlab r2014a, which does not support Xcode 8 for mex. Does this mean that I'm also not able to call the engine functions from C Code written in Xcode 8?
If there is no problem using Xcode 8 for this case (I hope so), an updated tutorial on how to configure an Xcode 8 Project would be great as I can't find some of the options mentioned in this 5 year old tutorial - Xcode seems to have changed a lot since then.

  0 Comments

Sign in to comment.

Products


Release

R2007a

Community Treasure Hunt

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

Start Hunting!