Main Content

Distribute MATLAB Interface to C++ Library

What Your MATLAB User Needs

To call functions in your 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 package name (calling syntax) is clib.libname.

  • The interface file that you created in the publishing step Build C++ Library Interface and Review Contents.

  • Any compiled library files included in the Libraries name-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.

PlatformShared LibraryFile Extension

Microsoft® Windows®

Dynamic-link library file

.dll

Linux®

Shared object file

.so

Apple macOS

Dynamic shared library file

.dylib

To determine if your library libname has run-time library dependencies, run these platform-specific commands from the operating system prompt.

  • Visual Studio® users

    dumpbin /dependents libname.dll
  • To find library dependencies on Windows systems, use the third-party product Dependency Walker. This free utility scans Windows modules and builds a hierarchical tree diagram of all dependent modules. For each module found, it lists all the functions exported by that module, and which of those functions are called by other modules. See How do I determine which libraries my MEX-file or stand-alone application requires? for information on using the Dependency Walker.

  • Linux platforms

    ldd -d libname.so
  • macOS platforms

    otool -L libname.dylib

Share Your Interface Files

If your MATLAB users have direct access to your files, such as through a shared network location, then copy all run-time dependent files to the same location as the interface file. 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 toolbox 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 Create and Share Toolboxes:

  • Select the Package Toolbox.

  • Set the toolbox folder to the folder that contains your interface file.

  • In the Toolbox Information field, choose a Toolbox Name. By default, the toolbox name is the name of the toolbox folder. The Toolbox Name becomes the .mltbx filename.

  • Provide Summary and Description text. For interface libname, identify the package name (calling syntax) as clib.libname.

  • Set the platform and release compatibility options in the Toolbox Portability field. 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 field.

If you built your interface from source code files only, then the only file you need to package is the interface file. The toolbox folder you specify in the Package Toolbox feature contains the interface file.

If you built the interface using the Libraries name-value argument, put the shared library files into the folder with the interface file. This folder should be the toolbox folder you specify in Package Toolbox.

If your interface has run-time library dependencies, then create a Getting Started Guide in the Examples, Apps, and Documentation field. When you create the guide, MATLAB opens a live script named GettingStarted.mlx in a doc subfolder within your toolbox 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 toolbox in the Add-On Manager. For more information, see Manage Add-Ons and Call Functions in C++ Compiled Library.

Related Topics