0
votes

I am aware that dll files created using MATLAB Compiler require MATLAB Compiler Runtime (MCR). So the question is: a) How do I initialize MCR using Python? b) How do I access the functions in the dll file, post MCR initialization?

I am using MATLAB R2012B, MCR v80 and Python 2.7.6 on Windows 7.

1
Does your question aim at the MATLAB specific issues or on how to call functions in a shared library from python in general?sebastian
The question is aimed particularly at MATLAB specific issues. I am not able to use functions in dll files generated by MATLAB compiler alone.Adarsh Chavakula

1 Answers

1
votes

Concerning the MATLAB "features", check this blog entry by Loren:

http://blogs.mathworks.com/loren/2011/02/03/creating-c-shared-libraries-and-dlls/

It shows a pretty complete example of how to create a shared library and how to use it. Quoting example code from that link, to initialize the MCR and the generated library you'll have to call:

// Initialize the MATLAB Compiler Runtime global state
if (!mclInitializeApplication(NULL,0))
{
    std::cerr << "Could not initialize the application properly."
              << std::endl;
    return -1;
}

// Initialize the Vigenere library
if( !libvigenereInitialize() )
{
    std::cerr << "Could not initialize the library properly."
              << std::endl;
    return -1;
}

Where you'll obviously have to replace libvigenere by your library's name.

Now you can call your generated matlab functions just as you would call any C function. And finally, shut down everything:

// Shut down the library and the application global state.
libvigenereTerminate();
mclTerminateApplication();

Concering the connection to python, there are multiple ways, all described e.g. in this question:

Calling C/C++ from python?