How to load a c++ dll file into Matlab


Question

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?

1
7
10/18/2011 6:38:49 PM

Accepted Answer

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.

4
2/19/2009 5:37:07 PM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon