Build on macOS and Linux Operating Systems
Set Run-Time Library Path
At run time, you must tell the macOS and Linux® operating system where the API shared libraries reside by setting an environment variable. The macOS or Linux command you use and the values you provide depend on your system architecture. Use this table for defining:
envvar
— the name of the environment variable.pathspec
— the value to assign toenvvar
.osfolder
— the folder that contains the platform-specific library.matlabroot
— the root folder of your MATLAB® installation.
Operating System | envvar | pathspec |
---|---|---|
macOS with Apple silicon |
|
|
macOS with Intel® |
|
|
Linux |
|
|
To set the library path, type:
envvar=pathspec
Replace the terms envvar
and
pathspec
with the appropriate values from the table. To specify
pathspec
, use matlabroot
and replace
osfolder
with the subfolder under /bin/
.
pathspec=matlabroot/bin/osfolder:matlabroot/sys/os/osfolder
For example, on a macOS with Apple silicon, replace osfolder
with
maca64
.
DYLD_LIBRARY_PATH=matlabroot/bin/maca64:matlabroot/sys/os/maca64
Build Application
To compile and link MAT-file programs, use the mex
script with the -client engine
option.
This example shows how to build the example matcreat.c
. Use this
example to verify the build configuration for your system. matcreat
is a
C program that demonstrates how to use the MAT-File API routines to create a MAT-file that
you can load into MATLAB.
To build the example, first copy the source code to a writable folder on your path.
copyfile(fullfile(matlabroot,'extern','examples','eng_mat','matcreat.c'),'.','f')
Use the following command to build it.
mex -client engine matcreat.c
To modify the build instructions for your particular compiler, use the -v
-n
options to view the current compiler and linker settings. Then, modify the
settings using the mex
option.varname
=varvalue