Main Content

Compile and Test a MATLAB Generated C Shared Library

This page explains how to compile the C driver code along with the C shared libraries. After compilation, you can test the complete C application.

Create the C shared library mentioned in the example Create a C Shared Library with MATLAB Code. MATLAB® Compiler SDK™ generates a wrapper file, a header file, and an export list when it creates a C shared library. The header file contains all of the entry points for all of the packaged MATLAB functions. The export list contains the set of symbols that are exported from a C shared library.

Once the shared library is created, you can integrate it with the C driver code as explained in Call a C Shared Library.For this example, the driver code matrix.c is located in matlabroot\extern\examples\compilersdk\c_cpp\matrix.

Compiling the Driver Application

To compile the driver code matrix.c, you use a C/C++ compiler. Execute the following mbuild command that corresponds to your development platform. This command uses your C/C++ compiler to compile the code and link the driver code against the MATLAB generated C shared library.

mbuild matrix.c libmatrix.lib

The .lib extension is for Windows®. On Mac, the file extension is .dylib, and on UNIX® it is .so.


This command assumes that the C shared library, the driver code, and the corresponding header file are in the current working folder.

This generates a standalone application, matrix.exe, on Windows, and matrix, on UNIX.

Testing the Application

These steps test the standalone C application and C shared library on your development machine.

  1. To run the application, add the folder containing the shared library that was created to your dynamic library path.

  2. Update the path for your platform by following the instructions in MATLAB Runtime Path Settings for Development and Testing.

  3. Run the driver application from the prompt (command prompt on Windows, shell prompt on UNIX) by typing the application name.

    For Windows, type matrix.exe.

    For Mac, type

    For UNIX, type matrix.

    The results are displayed as

    The sum of the matrix with itself is: 
    2.00		8.00		14.00	 
    4.00		10.00		16.00	 
    6.00		12.00		18.00	 
    The product of the matrix with itself is: 
    30.00		66.00		102.00	 
    36.00		81.00		126.00	 
    42.00		96.00		150.00		 
    The eigenvalues of the original matrix are: 
    16.12		-1.12		-0.00	 

See Also

Related Topics