Main Content


Initialize a library of MATLAB function asynchronously


FutureResult<std::shared_ptr<MATLABLib>> initMATLABLibraryAsync(MATLABApplication & application, const std::u16string & ctfPath)

FutureResult<std::shared_ptr<MATLABLib>> initMATLABLibraryAsync(MATLABApplication & application, const std::u16string & ctfPath, const std::u16string& session_key = std::u16string())

Initialize a library of MATLAB® function asynchronously to obtain a pointer to a freshly initialized C++ shared library once initialization is complete.

Optionally, you can specify the additional argument of a hex encoded 64 byte AES decryption key, which allows you to decrypt the library at runtime using the C++ API rather than a MEX loader.


MATLABApplication & application

MATLAB Application object returned from initMATLABApplication.

const std::u16string & ctfPath

Name of library. If path is omitted, it is assumed to be in the current folder. For information on how to use ctfPath, see matlab::cpplib::initMATLABLibrary.

const std::u16string& session_key = std::u16string()

AES decryption key, specified as a hex encoded AES key with a 64 byte file size.

For more details, see mcc -k.

Return Value


A std::future from which the status of initialization process, or a library pointer (once initialization is complete) can be obtained.



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


Library cannot be initialized.


Initialize MATLABLibrary Asynchronously, and Wait Until It Initializes

auto future = mc::initMatlabLibraryAsync(matlabApplication, 
if (!future.valid()) {
    throw std::future_error(std::future_errc::no_state);
std::future_status status;
do {
    status = future.wait_for(std::chrono::milliseconds(200));
    if (status == std::future_status::timeout) {
        std::cout << "Library initialization is in progress.\n";
    } else if (status == std::future_status::ready) {
        std::cout << "Library initialization has completed.\n";
} while (status != std::future_status::ready);
auto lib = future.get();

Version History

Introduced in R2018a