Distribute MATLAB Interface to C/C++ Library
R2026bWhat Your MATLAB User Needs
To call functions in your C/C++ library interface from their MATLAB® program, your users need:
Instructions for calling the functionality in your interface. If your interface name is
libname, then the MATLAB namespace (calling syntax) isclib.libname.The interface file that you created in the publishing step Build C/C++ Library Interface and Review Contents.
Any compiled library files included in the
Librariesname-value argument when you built the interface.Run-time dependency information, if any.
Interface files and compiled library files have these platform-specific file extensions.
| Platform | Compiled Library | File Extension |
|---|---|---|
Microsoft®Windows® | Dynamic-link library file | .dll |
Linux® | Shared object file | .so |
ApplemacOS | Dynamic shared library file | .dylib |
For more information, see How do I determine which libraries my MEX file or stand-alone application requires?
Share Your Interface Files
If your MATLAB users have direct access to your files, such as through a shared network
location, then run the Set up and copy run-time libraries section of
the clibPublishInterfaceWorkflow script to call the copyRuntimeDependencies function. Your users access the interface from this
location.
Alternatively, create a MATLAB add-on. For information, see Distribute Your Interface as an Add-On.
Distribute Your Interface as an Add-On
Use this workflow to provide your MATLAB users with the files and run-time dependency information by packaging the
files into a package installation (.mltbx)
file.
When the end-user runs the .mltbx file, MATLAB installs the interface and, if provided, library files and sets the
MATLAB path. For more information, see Get and Manage Add-Ons.
To create the .mltbx file, follow these instructions in Interactively Create and Share Packages:
Select the
Build Package.Set the package folder to the folder that contains your interface file.
In the Package Information section, choose a Package Name. By default, the package name is the name of the package folder. The Package Name becomes the
.mltbxfilename.Provide Summary and Description text. For interface
libname, identify the namespace (calling syntax) asclib.libname.Set the platform and release compatibility options in the Package Portability section. Clear the MATLAB Online check box.
If your interface has third-party library dependencies, create a Getting Started Guide in the Examples, Apps, and Documentation section.
If you built your interface from source code files only, then the only file you need to build is the interface file. The package folder you specify in the Build Package feature contains the interface file.
If you built the interface using the Libraries name-value argument,
then follow the steps in Share Your Interface Files using the folder
with the interface file. This folder must be the package folder you specify in
Build Package.
If your interface has run-time library dependencies and you can distribute them, then
follow the steps in Share Your Interface Files using the
additionalRuntimeDependencies or
additionalRuntimeFolders options for the
copyRuntimeDependencies function.
If you do not have permission to distribute the run-time libraries, then create a
Getting Started Guide in the Examples, Apps, and Documentation section.
When you create the guide, MATLAB opens a live script named GettingStarted.mlx in a doc
subfolder in your package folder. Provide instructions for installing dependent library
files that are available from an external source. These instructions must help the user
satisfy run-time dependencies. Users of your interface can view the Getting Started Guide
through the Options menu for the package in the Add-Ons panel. For more information, see
Manage Add-Ons and Call Functions in C/C++ Compiled Library.