MATLAB: Using mcc to compile a code that uses a .dll library

MATLABmcc compile .h .dll header

Hi,
I created a program in matlab with a GUI. I want to compile it to have an EXE. In the code, I use an external library, but I only have the files: foo.dll foo.h foo.lib.
In the matlab code I call: loadlibrary ('\foo', '\foo.h');
Later, I call some functions of those libraries, using: calllib('foo', 'Function', param);
I compile it using: mcc -m mycode.m -c
The compiler returns no errors, and a "mycode.exe" file is created. However, when I execute I get:
Error using loadlibrary (line 239) Deployed applications must use a prototype file instead of a header file. To create the prototype, use the loadlibrary mfilename option. Use the prototype file in compiled code. See http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/brb8oui.html for more information.
Error in mycode>mycode_OpeningFcn (line 66)
Error in gui_mainfcn (line 221)
Error in mycode (line 42)
Do you have any tip on how I can overcome this?
Thank you.

Best Answer

As the error message suggests, you cannot use a header file (.h) with loadlibrary in deployment mode. The link in the error: http://www.mathworks.com/help/toolbox/compiler/brb8oui.html provides step-by-step instructions on how you can generate a MATLAB prototype file (.m) and replace the .h file in your loadlibrary command with the generated .m file. The will fix the error and is also more efficient than providing a .h file. See here for more information about using prototype files with loadlibrary.