Main Content

Define Pathnames to Share Library Definition Files

You can share a MATLAB® interface to a C++ library, for example by uploading the library definition files to GitHub®. If another publisher has the same C++ library version and file structure as you, then they can download the definition files and build the interface.

The paths to the files used to generate the interface, such as the InterfaceGenerationFiles argument to the clibgen.generateLibraryDefinition function, contain file specifications based on the folder structure of your computer. To avoid hard-coded paths in the definition file, you can specify file paths relative to a starting path using the RootPaths name-value argument which is a dictionary. Then another publisher can build the interface by specifying the RootPaths argument based on the starting path on their computer.

Share defineMylib.m Library Definition File

This example shows how to create a library definition file defineMylib.m and associated data file MylibData.xml to share with another publisher. The C++ library consists of a header file school.hpp in folder C:\user1\libname. For an example using multiple headers and libraries, see the RootPaths argument description.

To share with another publisher, create a RootPaths dictionary argument with a key named pathKey and set the value to "C:\user1\libname". Another publisher locates the header file by updating the pathKey value to the start path of the library on their machine.

% Create RootPaths dictionary argument 
startpaths = dictionary; 
% Set key="pathKey" and value="C:\user1\libname"
startpaths("pathKey") = "C:\user1\libname"; 

Identify Variables with Relative Pathnames with Keys in RootPaths Dictionary

To specify school.hpp in the InterfaceGenerationFiles argument, create a string with the key name inside "<" and ">" tags.


The function uses the value specified for the key in a RootPaths dictionary and creates the pathname C:\user1\libname\school.hpp.

Create Library Definition Files

Set the RootPaths argument.

clibgen.generateLibraryDefinition("<pathKey>/school.hpp", ...
    RootPaths=startpaths, ...

Share Library Files with Another Publisher

Share the library definition files defineMylib.m and MylibData.xml and provide path information to another publisher. In this example, each publisher uses the RootPaths key pathKey to locate the school.hpp header file in their library folders.

Another Publisher Builds the Definition File

From your information, the other publisher locates the school.hpp header file in the folder C:\user2\libname on their computer. To set the RootPaths key pathKey to this folder, type:

libdef = defineMylib;
libdef.RootPaths("pathKey") = "C:\user2\libname";

Build the definition file.

See Also