Compile MATLAB code into a standalone executable

runmat compile turns a MATLAB program into one executable file. Copy it to a Windows, macOS or Linux computer and run it there. That computer doesn't need MATLAB, RunMat or a separate runtime.

main.m
% Find a bearing defect from a vibration signal
fs = 20000;
t = (0:fs-1)' / fs;
x = bearingSignal(t, 125);
env = abs(hilbertEnvelope(x));
[f, P] = spectrumOf(env - mean(env), fs);
[~, i] = max(P(2:end));
fprintf("Defect frequency: %.1f Hz\n", f(i + 1));
terminal
$ runmat compile main.m -o bearing
Compiled bearing
$ ./bearing
Defect frequency: 125.0 Hz

What a compiled program does

Runs without an install

The runtime is built into the executable. The computer only needs Windows, macOS or Linux.

Same results as in RunMat

A compiled program gives the results you get running the code in RunMat, including math that runs on the GPU.

MEX files and C libraries go inside

MEX files and C libraries your program loads are built into the executable, so you ship one file.

Build with runmat compile

Write and test your program in RunMat, then run runmat compile. It checks your code the same way runmat check does. If it finds an error, the build stops and shows the line and the reason.

Windowsx86-64
macOSApple silicon and Intel
Linuxx86-64

runmat compile builds for the machine it runs on. To ship to several platforms, build on each one, for example on CI runners.

Where to run a compiled program

Test rigs and lab PCs
Run your analysis on the rig's own computer right after each test.
Colleagues and customers
Send the executable. They double-click it or run it from a terminal, with no scripts or paths to set up.
Servers and CI
Run it as a pipeline step or a scheduled job. The runner needs only the executable.
Your cluster
Remote jobs send the compiled program to the workers, so they run it without a copy of your project.

Include only the functions you use

By default the executable includes the whole RunMat runtime. If every call in your program is known before it runs, --policy=closed-world links only the functions it uses.

The current release (0.7.0) doesn't yet remove all unused code from native builds, so compiled programs can be larger than they need to be. They will get smaller by RunMat 1.0. Size is the only effect: compiled programs work the same and give the same results.

Defaultrunmat compile main.m
The whole runtime. Code that picks functions while it runs, such as feval on a computed name, works as usual.
Closed-world--policy=closed-world
Only the functions your program uses. The build stops and names the call if one can't be known ahead of time.

FAQ

01Does the computer that runs it need MATLAB or RunMat?

No. Copy the executable to the computer and run it. Nothing else needs to be installed.

02Can I give the executable to other people?

Yes. Anyone can share programs compiled with RunMat, and anyone can run them for free. At organizations with more than 250 employees and contractors or more than $10M in annual revenue, a person with a Professional seat can run programs they compiled on up to three computers they use; running compiled programs on other servers or clusters, or selling them as part of a product, needs an Enterprise license.

RunMat license

03Which platforms can I build for?

Windows (x86-64), macOS (Apple silicon and Intel) and Linux (x86-64). Each build is for the computer you run runmat compile on, so to ship to all three, build on each one, for example in CI.

04Does a compiled program use the GPU?

Yes. Array math runs on the GPU as it does in RunMat, on NVIDIA, AMD, Intel and Apple GPUs, with no GPU code to write.

05How is this different from packaging code with a runtime installer?

With a runtime installer, the person running your program installs a separate runtime first. A RunMat executable has the runtime built in, so they run the one file.

06Can I see what's inside the executable?

Yes. runmat compile --explain-link lists every function in the executable and the line of your code that needed it. --link-plan-json writes the same list as a file, for example to keep with each CI build.

All compile options