0

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.

2
  • Does your question aim at the MATLAB specific issues or on how to call functions in a shared library from python in general? Commented May 22, 2014 at 6:24
  • The question is aimed particularly at MATLAB specific issues. I am not able to use functions in dll files generated by MATLAB compiler alone. Commented May 22, 2014 at 6:40

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

This method involves using C or C++ (C++ in this case) wrapper function to initialize MCR and subsequently load the libraries and use functions in them. However I do not intend to use C or C++ at all. I want to be able to call dlls using python. ctypes.cdll is a way to load C shared dlls but I cannot access the functions in the dlls when they are created using MATLAB compiler.
Why not? mclInitializeApplication should be a plain C function, that you can call e.g. with ctypes from python. All that's done in this example in C++ can be translated to python using ctypes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.