Using mcc to compile a code that uses a .dll library
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nuno Almeida
el 12 de Mzo. de 2012
Comentada: kaa417
el 6 de Jun. de 2016
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.
0 comentarios
Respuesta aceptada
Kaustubha Govind
el 12 de Mzo. de 2012
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.
4 comentarios
Image Analyst
el 15 de En. de 2013
That page does not give step by step directions. It merely points you to the help for loadlibrary:
How to Create a Prototype File. To create a prototype file, use the mfilename option of the loadlibrary function.
and the loadlibrary page does not give you directions either. All it says is:
loadlibrary(libname,@protofile) uses a prototype file, protofile, in place of a header file.
but that's just how to use an existing prototype file that you have created. It also has this:
'mfilename' — Prototype filestring
Prototype file, specified as the comma-separated pair consisting of 'mfilename' and a string. Generates a prototype file in the current folder. The prototype file name must be different from the library name. Use this file in place of a header file when loading the library.
It doesn't tell you how to pass in your .h file. That's not really instructions, much less step by step, on creating a prototype file, is it? In fact the example for building a prototype file step-by-step is missing (all the other uses have examples though, but not for prototype). This page does have some stuff, but it's not really clear what each argument to loadlibrary is.
Más respuestas (2)
Nuno Almeida
el 13 de Mzo. de 2012
2 comentarios
Kaustubha Govind
el 13 de Mzo. de 2012
You need to manually add the file ADCacquire.m to the CTF archive of the compiled application. You can do this with the -a option (if using the mcc command) or drag it under "Other/Additional Files" if using deploytool. Normally, the MATLAB Compiler analyzes your code and automatically locates all the MATLAB files called from your code, but your call to mexCallMATLAB is probably opaque to MATLAB Compiler.
Ver también
Categorías
Más información sobre Standalone Applications en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!