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 mentioned in the example see Create a C Shared Library with MATLAB Code.

  2. Locate the matrix.c file in matlabroot\extern\examples\compilersdk\c_cpp\matrix.

     C Code to Implement Shared Library

    Copy and paste this file in the for_testing folder created when you generated the C shared library.

  3. Use the system command line to navigate to the for_testing folder where matrix.c exists.

  4. To compile and link the application, use mbuild at the system command line.

    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.

    matrixThe 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