Skip to Main Content Skip to Search
Product Documentation

Compiling and Linking MAT-File Programs

Building on UNIX Operating Systems

To build on a UNIX operating system, refer to Setting Run-Time Library Path and Using the Options File.

Setting Run-Time Library Path

At run time, you must tell the UNIX operating system where the API shared libraries reside by setting an environment variable. The UNIX command you use and the values you provide depend on your shell and system architecture. The following table lists the name of the environment variable (envvar) and the values (pathspec) to assign to it. The term matlabroot refers to the root folder of your MATLAB installation.

Operating Systemenvvarpathspec

32-bit Linux®

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 Apple Macintosh (Intel®)

DYLD_LIBRARY_PATH

matlabroot/bin/maci64: matlabroot/sys/os/maci64

Using the C Shell.  Set the library path using the command:

setenv envvar pathspec

Replace the terms envvar and pathspec with the appropriate values from the table. For example, on a Macintosh system use:

setenv DYLD_LIBRARY_PATH
matlabroot/bin/maci64:matlabroot/sys/os/maci64

You can place these commands in a startup script, such as ~/.cshrc.

Using the Bourne Shell.  Set the library path using the command:

envvar = pathspec:envvar
export envvar

Replace the terms envvar and pathspec with the appropriate values from the table. For example, on a Macintosh system use:

DYLD_LIBRARY_PATH=matlabroot/bin/maci64:matlabroot/sys/os/maci64:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH 

You can place these commands in a startup script such as ~/.profile.

Using the Options File

The MATLAB options file for UNIX systems, matopts.sh, lets you use the mex script to easily compile and link MAT-file applications. The options file is in matlabroot/bin. Use the -f switch to specify the name and location of the options file.

For example, to compile and link the matcreat.c example, first copy the file to a writable folder, such as c:\work, on your path:

copyfile(fullfile(matlabroot, 'extern', 'examples', 'eng_mat', ...
  'matcreat.c'), fullfile('c:', 'work'));

Use the following command to build it:

mex('-v', '-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. Then, make the appropriate changes in a local copy of the matopts.sh file.

Building on Windows Operating Systems

To compile and link MAT-file programs, use the mex script with a MAT options file. Use the -f switch to specify the name and location of the options file. There are different options files for the supported compilers and operating systems, as shown in the following table.

Operating SystemDefault Options File

32-bit Windows

matlabroot\bin\win32\mexopts\*engmatopts.bat

64-bit Windows

matlabroot\bin\win64\mexopts\*engmatopts.bat

The * character in the file name, *engmatopts.bat, represents the compiler type and version. For example, the options file to use with the Microsoft Visual C++ Version 9.0 compiler is msvc90engmatopts.bat. To build the matcreat.c application with this compiler, first copy the following file to a writable folder, such as c:\work, on your path:

copyfile(fullfile(matlabroot, 'extern', 'examples', 'eng_mat', ...
  'matcreat.c'), fullfile('c:', 'work'));

Use the following command to build it:

mex('-v', '-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. Then, make the appropriate changes in a local copy of the options file.

Deploying MAT-File Applications

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.

Third-Party Data Files

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 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 icudt40b.dat. For systems that order bytes in a little-endian manner, use icudt40l.dat.

For deployed applications, be sure to distribute the MATLAB lcdata.xml file from the matlabroot/bin/ folder, and the matlabroot/resources/MATLAB/ folder with your standalone program.

Third-Party Libraries

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

WindowsLinuxMacintosh (Intel)
libmat.dlllibmat.solibmat.dylib
libmx.dlllibmx.solibmx.dylib

In addition to these libraries, you must have all third-party library files that libmat requires. 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. Determine the libraries using the platform-specific methods described in the following table.

Library Dependency Commands

WindowsLinuxMacintosh

Use Dependency Walker

ldd -d libmat.sootool -L libmat.dylib

Dependency Walker.  On Windows systems, to find library dependencies, use the third-party product Dependency Walker. 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 called by other modules. 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.

Drag and drop the file matlabroot/bin/win32/libmat.dll or matlabroot/bin/win64/libmat.dll into Depends window.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS