| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
Compiling and Linking on UNIX Operating Systems Compiling and Linking on Windows Operating Systems |
At run-time, you must tell the UNIX[1] operating system where the API shared libraries reside. These sections provide the necessary UNIX commands, depending on your shell and system architecture.
Set the library path as follows for the C and Bourne shells. Replace the terms envvar and pathspec with the appropriate values from the following table.
In the C shell, set the library path using the command:
setenv envvar pathspec
In the Bourne shell, use:
envvar = pathspec:envvar export envvar
| Operating System | envvar | pathspec |
|---|---|---|
Linux®[a] | LD_LIBRARY_PATH | matlabroot/bin/glnx86: matlabroot/sys/os/glnx86 |
64-bit Linux | LD_LIBRARY_PATH | matlabroot/bin/glnxa64: matlabroot/sys/os/glnxa64 |
64-bit SunSolaris SPARC® | LD_LIBRARY_PATH | matlabroot/bin/sol64: matlabroot/sys/os/sol64 |
Apple® Macintosh® (Intel®) | DYLD_LIBRARY_PATH | matlabroot/bin/maci: matlabroot/sys/os/maci |
[a] Linux is a registered trademark of Linus Torvalds. | ||
For example, for the C shell on a Solaris system use:
setenv LD_LIBRARY_PATH matlabroot/bin/sol64:matlabroot/sys/os/sol64
and for the Bourne shell:
LD_LIBRARY_PATH=matlabroot/bin/sol64:matlabroot/sys/os/sol64:$LD_LIBRARY_PATH export LD_LIBRARY_PATH
You can place these commands in a startup script such as ~/.cshrc for C shell or ~/.profile for Bourne shell.
The MATLAB options file, matopts.sh, lets you use the mex script to easily compile and link MAT-file applications. For example, to compile and link the matcreat.c example, first copy the file using the command:
matlabroot/extern/examples/eng_mat/matcreat.c
to a writable folder, then use the following command to build it:
mex -f matlabroot/bin/matopts.sh matcreat.c
If you need to modify the options file for your particular compiler or platform, use the -v switch to view the current compiler and linker settings and then make the appropriate changes in a local copy of the matopts.sh file.
To compile and link Fortran or C MAT-file programs, use the mex script with a MAT options file. The MAT options files reside in matlabroot\bin\win32\mexopts or matlabroot\bin\win64\mexopts and are named *engmatopts.bat, where * represents the compiler type and version.
For example, to compile and link the stand alone MAT application matcreat.c using the Microsoft® Visual C++® Version 9.0 compiler on a Microsoft Windows operating system, first copy the file:
matlabroot\extern\examples\eng_mat\matcreat.c
to a writable folder, and then use the following command to build it:
mex -f matlabroot\bin\win32\mexopts\msvc90engmatopts.bat matcreat.c
If you need to modify the options file for your particular compiler, use the -v switch to view the current compiler and linker settings and then make the appropriate changes in a local copy of the options file.
MATLAB requires the following data and library files for building any MAT-file application. You must also distribute these files along with any MAT-file application that you deploy to another system.
When building a MAT-file application on your system or deploying a MAT-file application to some other system, make sure that the appropriate Unicode data file is installed in the matlabroot/bin/$ARCH folder. MATLAB uses this file to support Unicode encoding.
For systems that order bytes in a big-endian manner, use icudt32b.dat.
For systems that order bytes in a little-endian manner, use icudt32l.dat.
When building a MAT-file application on your system or deploying a MAT-file application to some other system, make sure to install the appropriate libraries in the matlabroot/bin/$ARCH folder:
Library File Names by Operating System
| Windows | UNIX | Macintosh (Intel) |
|---|---|---|
| libmat.dll | libmat.so | libmat.dylib |
| libmx.dll | libmx.so | libmx.dylib |
In addition to these libraries, you must also have all third-party library files that libmat depends on. MATLAB uses these additional libraries to support Unicode character encoding and data compression in MAT-files. These library files must reside in the same folder as libmx.
You can determine what most of these libraries are using the platform-specific methods described below.
Type the following command:
ldd -d libmat.so
Type the following command:
otool -L libmat.dylib
On Windows systems, the third-party product Dependency Walker can be used to diagnose errors related to loading and executing modules. Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module and builds a hierarchical tree diagram of all dependent modules. For each module found, it lists all the functions that are exported by that module, and which of those functions are actually being called by other modules. You can download the Dependency Walker utility from the following Web site:
http://www.dependencywalker.com/
See the Technical Support solution 1-2RQL4L for information on using the Dependency Walker:
http://www.mathworks.com/support/solutions/data/1-2RQL4L.html
Drag and drop the file matlabroot/bin/win32/libmat.dll or matlabroot/bin/win64/libmat.dll into Depends window.
If you need to manipulate Unicode text directly in your application, the latest version of International Components for Unicode (ICU) is freely available online from the IBM® Corporation Web site at:
http://icu.sourceforge.net/download
[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
[a] Linux is a registered trademark of Linus Torvalds.
![]() | Examples of MAT-Files | MATLAB Interface to Shared Libraries | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |