Main Content


Initialize a library of MATLAB functions packaged in a deployable archive file


std::unique_ptr<MATLABLibrary> initMATLABLibrary(std::shared_ptr<MATLABApplication> application, const std::u16string & ctfPath)

Initialize a library of MATLAB® functions packaged in a deployable archive (CTF) file, and return a unique pointer to the library. As parameters, it takes a shared pointer to a MATLABApplication instance and a path to the CTF.

The path to the deployable archive is either relative or absolute. If the path is relative, the following paths are prepended in the order specified below until the file is found or all possibilities are exhausted.

  • the value of the environment variable CPPSHARED_BASE_CTF_PATH, if defined

  • the working folder

  • the folder where the executable is located

  • on Mac: the folder three levels above the folder where the executable is located (for example, if the executable is generic_interface/, the folder used is generic_interface)

If the library is found, it is initialized and a pointer to it is returned. Otherwise,an exception is thrown.


std::shared_ptr<MATLABApplication> application

Pointer to a MATLABApplication object returned from initMATLABApplication.

const std::u16string & ctfPath

Path (relative or absolute) to archive.

Return Value


Pointer to a MATLABLibrary object that is used to call functions from the library, feval etc.



No library with the given name is found on the shared library path.


Library cannot be initialized.


Initialize MATLABLibrary

std::vector<std::u16string> opts = {u"-nojvm"};
auto matlabPtr = initMATLABApplication(MATLABApplicationMode::IN_PROCESS, opts);
auto libAstro = initMATLABLibrary(matlabPtr, convertUTF8StringToUTF16String("astro.ctf"));

Version History

Introduced in R2018a