Main Content

Requirements to Build Engine C Applications

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.

MATLAB includes the engine and data APIs you need to work with MATLAB code and data in C programs. Additionally, you need to install a supported compiler, configure MATLAB to use the compiler, and configure your run-time environment. To set up your C development environment, see Set Up C Development Environment.

MATLAB Engine and Data APIs

MATLAB provides APIs for working with MATLAB in C programs. These APIs are installed on your system when you install MATLAB.

  • MATLAB engine API for C — Use this API so that your program can interact with MATLAB. For the complete API, see Call MATLAB from C.

  • MATLAB C Matrix API — Use this API to handle the data exchange between MATLAB and C. For more information, see C Matrix API.

Supported Compilers

For an up-to-date list of supported compilers, see Supported and Compatible Compilers on the MathWorks® website.

Build with mex Command

If you use the MATLAB Editor to write your C application code, then you can configure and run the mex command to build it. This command sets up the compiler for C++ applications.

mex -setup -client engine c

This command builds the application engwindemo.c.

mex -v -client engine engwindemo.c

Set Run-Time Library Path

To run your application, configure your run-time environment by adding one of these environment variables to the specified path. When specifying these paths, replace matlabroot with the path returned by the MATLAB matlabroot command.

Operating SystemVariablePath

Windows®

PATH

fullfile(matlabroot,"bin","win64")

macOS with Apple silicon

DYLD_LIBRARY_PATH

fullfile(matlabroot,"bin","maca64")

Linux®

LD_LIBRARY_PATH

fullfile(matlabroot,"bin","glnxa64"):fullfile(matlabroot,"sys","os","glnxa64")

For example, if your matlabroot on Windows is C:\Program Files\MATLAB\R2024b, then this system prompt command sets the run-time environment variable PATH:

set PATH=C:\Program Files\MATLAB\R2024b\bin\win64;%PATH%

See Also

Topics