This example shows how to create a C/C++ shared library using a MATLAB® function.
To examine the MATLAB code that you want to deploy
as a shared library, open
function a = addmatrix(a1, a2) a = a1 + a2;
To test your function, at the MATLAB command prompt,
The output appears as follows:
ans = 3
To open the Library Compiler app, enter the following command at the MATLAB command prompt:
In the Application Type section of the toolstrip, select C++ Shared Library from the list.
Specify the MATLAB functions you want to deploy.
In the Exported Functions section of the toolstrip, click the plus button.
In the file explorer that opens, locate and select the
addmatrix.m is located in
Click Open to select the file and close the file explorer.
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.
The Package window opens while the library is being generated.
Select the Open output folder when process completes check box.
Click Close on the Package window.
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
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.