This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Create a C/C++ Shared Library with MATLAB Code

This example shows how to create a C/C++ shared library using a MATLAB® function.

  1. To examine the MATLAB code that you want to deploy as a shared library, open addmatrix.m.

    function a = addmatrix(a1, a2)
    a = a1 + a2;
  2. To test your function, at the MATLAB command prompt, enter addmatrix(1,2).

    The output appears as follows:

    ans =
  3. To open the Library Compiler app, enter the following command at the MATLAB command prompt:

    >> libraryCompiler

  4. In the Application Type section of the toolstrip, select C++ Shared Library from the list.

  5. Specify the MATLAB functions you want to deploy.

    1. In the Exported Functions section of the toolstrip, click the plus button.

    2. In the file explorer that opens, locate and select the addmatrix.m file.

      addmatrix.m is located in matlabroot\extern\examples\compilersdk.

    3. Click Open to select the file and close the file explorer.

  6. In the Packaging Options section of the toolstrip, verify that the Runtime downloaded from web check box is selected.

    This option creates an application installer that automatically downloads the MATLAB Runtime and installs it along with the deployed shared library.

  7. Click Package.

    The Package window opens while the library is being generated.

  8. Select the Open output folder when process completes check box.

  9. Click Close on the Package window.

  10. Verify the contents of the generated output:

    • for_redistribution — A folder containing the installer to distribute the standalone application

    • for_testing — A folder containing the raw files generated by the compiler

    • for_redistribution_files_only — A folder containing only the files needed to redistribute the application

    • PackagingLog.txt — A log file generated by the compiler.

If you are integrating this C/C++ shared library into a C/C++ application and want to test the application, see Integrate a C/C++ Shared Library into an Application.

Was this topic helpful?