tags:

views:

1893

answers:

3

I have a C++ dll file that uses a lot of other c++ librarys (IPP, Opencv +++) that I need to load into matlab. How can I do this?

I have tried loadlibrary and mex. The load library does not work.

The mex finds the linux things (platform independent library) and tries to include them. And that does not work.

Does anyone have any good ideas?

A: 

You could go for the Java approach (since Matlab runs on a JRE and can access Java objects/methods -- just be aware that the Matlab JRE is not as up-to-date as the latest JRE, the one I'm running uses Java 1.5) and use JNA to access your DLL.


Or, if you wrote the top-level DLL, you could go for the COM/ActiveX approach.

I've had good success architecting the interface to my C++ functions as COM/ActiveX libraries -- you don't have to bother with that .h stuff.

See the External Interfaces guide on COM clients, particularly the part about managing/converting data.

It would be extra work to add the COM/ActiveX layer, but would make your library more portable within the Windows world and probably more easily used in MATLAB.


If you have a lot of function calls to your DLL, the COM/ActiveX approach might be faster (not sure), but otherwise I think the JNA approach would be easier.

Jason S
A: 

loadlibrary should work. I use it all the time to call functions from dlls written in C++ with C wrappers.

What errors are you getting when you try to use loadlibrary?

Make sure that the exported functions of the dll are C functions, not C++ functions. If not, then write C wrappers.

More info on exactly what you are doing when using loadlibrary would be helpful.

Dima
+1  A: 

As mentioned by others, you should first wrap your C++ library as a C library - mathworks used to advise not to use C++ code directly in mex (dlopening C++ core directly is complicated), maybe it is still true.

Your description is quite unclear, too: what do you mean by "mex finds the linux thing", but that does not work. Saying that it does not work is not helpful: the exact commands and error message are.

David Cournapeau