Main Content

Call Functions in Linux Interface to C++ Shared Library

Set MATLAB Path to Interface and Library Folder

If you created the matrixOperations interface in the example Header File and Shared Object File on Linux, then you can use it in this example. Navigate to the folder you used to create the matrixOperations interface file.

Put the shared library file in the folder with the MATLAB® interface file.

copyfile(fullfile(productPath,"glnxa64","*.so"),".","f")

Call addpath on the interface folder.

View Help

At the MATLAB command prompt, display help for the interface. In the example, the clibgen.generateLibraryDefinition command changed the name of the interface to matrixOperations to matrixlib. Type this command to load the package.

doc clib.matrixlib.Mat

To display the members of the package, type:

doc clib.matrixlib
Classes contained in clib.matrixlib:
Mat             - clib.matrixlib.Mat    Representation of C++ class Mat

Functions contained in clib.matrixlib:
addMat          - clib.matrixlib.addMat    Representation of C++ function addMat
updateMatByX    - clib.matrixlib.updateMatByX    Representation of C++ function updateMatByX
updateMatBySize - clib.matrixlib.updateMatBySize    Representation of C++ function updateMatBySize

To display signatures for the package function, click the links for addMat, updateMatByX, and updateMatBySize.

clib.matrixlib.addMat    Representation of C++ function addMat
  inputs
    mat            read-only clib.matrixlib.Mat
  outputs
    RetVal         int32

clib.matrixlib.updateMatByX    Representation of C++ function updateMatByX
  inputs
    mat            clib.matrixlib.Mat
    X              int32
  outputs

clib.matrixlib.updateMatBySize    Representation of C++ function updateMatBySize
  inputs
    mat            clib.matrixlib.Mat
    arr            int32
  outputs

To display information about class clib.matrixlib.Mat, click the link for Mat.

clib.matrixlib.Mat    Representation of C++ class Mat
Method Summary:
  Mat                 - clib.matrixlib.Mat    Constructor of C++ class Mat
  Mat                 - clib.matrixlib.Mat    Constructor of C++ class Mat
  setMat              - clib.matrixlib.Mat.setMat    Method of C++ class Mat
  getMat              - clib.matrixlib.Mat.getMat    Method of C++ class Mat
  getLength           - clib.matrixlib.Mat.getLength    Method of C++ class Mat
  copyMat             - clib.matrixlib.Mat.copyMat    Method of C++ class Mat

To display constructor and method signatures, use the methods or methodsview functions. For example, type:

methodsview clib.matrixlib.Mat

Call Library Functions

Test the functions in the interface. For example, type:

matObj = clib.matrixlib.Mat;   % Create a Mat object
intArr = [1,2,3,4,5];
matObj.setMat(intArr);     % Set the values to intArr
retMat = matObj.getMat(5)  % Display the values
retMat =

  1×5 int32 row vector

   1   2   3   4   5

Related Topics