Hauptinhalt

Build and Run C Engine Application on macOS

Note

The MATLAB® Engine API for C++ is recommended over the Engine API for C. The MATLAB Engine API for C++ includes modern C++ features for writing engine applications. For more information, see Call MATLAB from C++. There are no plans to remove the Engine API for C.

This example shows how to verify the build process on a macOS platform using the C example engdemo.c. Make note of the value of matlabroot, the folder where MATLAB is installed.

Open MATLAB.

Verify your current folder is writable and copy the example.

copyfile(fullfile(matlabroot,"extern","examples","eng_mat","engdemo.c"),".","f")

Build the application.

mex -v -client engine engdemo.c

Set the system path. Make sure that you include the : path terminator character.

setenv PATH matlabroot/bin:$PATH

Set the run-time library path and run the example. The example assumes that the engdemo application is on your system path.

DYLD_LIBRARY_PATH=matlabroot/bin/maca64:matlabroot/sys/os/maca64 ./engdemo

MATLAB starts and displays a figure. To close the figure, press Return.

Create variable X, for example:

X = "hello"

MATLAB displays the results and closes.

See Also

Topics