Main Content

Implement a C Shared Library with a Driver Application

This example shows how to call a C shared library built with MATLAB® Compiler SDK™ from a C application.

  1. Create the C shared library as specified in the example Create a C Shared Library with MATLAB Code.

  2. Locate the matrix.c file located in matlabroot\extern\examples\compilersdk\c_cpp\matrix or your work folder.

     C Code to Implement Shared Library

    Copy and paste this file in the folder that contains your C shared library. If you used the Library Compiler, it is located in the for_testing folder.

  3. At the system command prompt, navigate to the folder where you copied matrix.c.

  4. Use mbuild to compile and link the application.

    mbuild matrix.c libmatrix.lib

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

  5. From the system command prompt, run the application.

    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