All Articles / Application Notes

Packaging Zaber Motion Library with MATLAB Compiler

GitHubSource Code

By Software Team

Published on Mar. 04, 2026

This example demonstrates how to build and run a standalone MATLAB application which uses the Zaber Motion Library toolbox.
The source code for the application is in src/main.m.

MATLAB Compiler

MATLAB Compiler is a tool which allows users to package MATLAB code into standalone applications.
During the build process, it will perform a dependency analysis of a project to determine exactly which files
need to be included in the final packaged application, but binary dependencies such as mex files and shared libraries
will not be included automatically.

The Zaber Motion Library toolbox includes some binary dependencies, namely a shared library (dll/so/dylib) and
its corresponding thunk file, so the paths to these binary files must be specified manually.

Prerequisites

The user must have the MATLAB Compiler and Zaber Motion Library toolbox (version >=8.4.0) installed.
Additionally, in order to run the matlab batch commands below, MATLAB must be added to the system PATH.

This code example has been tested with MATLAB R2025b.

Building the Application

There are several different ways of configuring MATLAB Compiler to build a standalone application.
In this example we use the compiler.build.standaloneApplication function with StandaloneApplicationOptions object,
It is also possible to configure and build an application using the Standalone Application Compiler in the MATLAB IDE.

The build_standalone_app.m script contains all the logic for setting up and building an app with the Zaber Motion Library toolbox.
The most important thing to note is the following line where we assign the return value from zaber.motion.Helper.getCompilerDependencies
to the AdditionalFiles field of the build options object:

buildOpts.AdditionalFiles = zaber.motion.Helper.getCompilerDependencies();

You can run the script either in your MATLAB IDE, or from the command line with:

cd examples/util_matlab_compiler
matlab -batch "build_standalone_app"

Note: If you are using the Standalone Application Compiler in the MATLAB IDE, the files whose paths are returned from zaber.motion.Helper.getCompilerDependencies need to be added manually under "Files Required for Standalone to Run".

Running the Application (Windows)

To run the application on Windows, you can either locate and run the exe directly from File Explorer, or in powershell:

cd examples/util_matlab_compiler
.\ZaberTestApp\output\build\ZaberTestApp.exe

Running the Application (Linux/macOS)

On Linux/macOS, MATLAB Compiler generates a shell script run_ZaberTestApp.sh which requires the path to your MATLAB Runtime (or MATLAB installation) as the first argument:

cd examples/util_matlab_compiler
./ZaberTestApp/output/build/run_ZaberTestApp.sh <deployedMcrRoot>

Where is the path to your MATLAB install.