Set Up C Development Environment
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.
To integrate MATLAB functions into C applications, you need to set up your development environment.
You can use the MATLAB desktop to create your MATLAB functions, write C application code, and integrate the two. The MATLAB desktop environment can be used across platforms.
You can also use an integrated development environment (IDE), such as Microsoft® Visual Studio® or Xcode.
Set Up MATLAB Desktop for Development (Windows, Linux, and macOS)
At the MATLAB command prompt, configure a C compiler for use with your application.
mex -setup -client engine c
Author your C application code. You also can use one of these examples.
fullfile(matlabroot,"extern","examples","eng_mat","engwindemo.c") % for Windows fullfile(matlabroot,"extern","examples","eng_mat","engdemo.c")
Compile and link your C application code using the
mexfunction.mex -client engine engwindemo.c
Set Up Integrated Development Environment
To use an integrated development environment (IDE), such as Visual Studio or Xcode, set up your environment for building standalone C applications using the
following libraries and include files. It is recommended that you first compile your C
application with the mex function in MATLAB using the verbose mode. This mode displays all the files you need to include
in your development environment.
Engine Include Files
Header files contain function declarations with prototypes for the routines you access
in the API libraries. These files are in the
fullfile(matlabroot,"extern","include") folder and are the same for
Windows®, macOS, and Linux® systems.
engine.h— Function prototypes for engine routines.matrix.h— Definition of themxArraystructure and function prototypes for matrix access routines.mat.h(optional) — Function prototypes for MAT file (mat) routines.
In your IDE, set the pre-processor include path to the value returned by this MATLAB command:
fullfile(matlabroot,"extern","include")
Engine Libraries
You need the libeng and libmx shared libraries.
The name of the file is platform-specific. Add these library names to your IDE
configuration. Refer to your IDE product documentation for instructions.
Windows Libraries
In these path specifications, replace compiler with either
"microsoft" or "mingw64".
Engine library —
fullfile(matlabroot,"lib","win64",compiler,"libeng.lib")Matrix library —
fullfile(matlabroot,"lib","win64",compiler,"libmx.lib")MEX library (optional) —
fullfile(matlabroot,"lib","win64",compiler,"libmex.lib")MAT-File library (optional) —
fullfile(matlabroot,"lib","win64",compiler,"libmat.lib")
Linux Libraries
Engine library —
fullfile(matlabroot,"bin","glnxa64","libeng.so")Matrix library —
fullfile(matlabroot,"bin","glnxa64","libmx.so")MEX library (optional) —
fullfile(matlabroot,"bin","glnxa64","libmex.so")MAT-File library (optional) —
fullfile(matlabroot,"bin","glnxa64","libmat.so")
macOS Libraries
Engine library —
fullfile(matlabroot,"bin","maca64","libeng.dylib")Matrix library —
fullfile(matlabroot,"bin","maca64","libmx.dylib")MEX library (optional) —
fullfile(matlabroot,"bin","maca64","libmex.dylib")MAT-File library (optional) —
fullfile(matlabroot,"bin","maca64","libmat.dylib")