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

11 ビュー (過去 30 日間)
Nuno Almeida
Nuno Almeida 2012 年 3 月 12 日
コメント済み: kaa417 2016 年 6 月 6 日
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.

採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 3 月 12 日
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 件のコメント
Image Analyst
Image Analyst 2013 年 1 月 15 日
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.
kaa417
kaa417 2016 年 6 月 6 日
hi ,have you solve this problem?

サインインしてコメントする。

その他の回答 (2 件)

Nuno Almeida
Nuno Almeida 2012 年 3 月 13 日
Thanks. Of course I should have had placed more attention on the error message. Here's how I solved it, and it worked ok. Call this once in the matlab prompt: loadlibrary('foo', 'foo.h', 'mfilename', 'lib_matlab.m');
Then, inside the code, replaced the loadlibrary call for this: loadlibrary ('foo', @lib_matlab);

Nuno Almeida
Nuno Almeida 2012 年 3 月 13 日
Furthermore, a new (related) issue:
in my matlab code (which I have just compiled), I call a mex c function ( [y1, y2] = fast_loops(x1, x2); ). This function was written in C, and compiled with mex. Inside the C function, I do some calculations and call a function from matlab ( mexCallMATLAB(2,lhs,1,&rhs, "ADCacquire"); ).
I have this matlab function in the same directory as the rest of the code, libraries, etc. It is a file called "ADCacquire.m" beginning with: [time signal] = ADCacquire(length)
When I run the main code from the MATLAB prompt, it works ok. However, after compiling it with mcc, and running the .EXE, the program runs with no problem until it gets to the part where fast_loops is called. Then an error is returned to the commandline:
" Error using fast_loops
Undefined function 'ADCacquire' for input arguments of type 'double'. "
Do you have any idea on why it is not locating the function, and how can I solve this?
Thank you.
  2 件のコメント
Kaustubha Govind
Kaustubha Govind 2012 年 3 月 13 日
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.
Nuno Almeida
Nuno Almeida 2012 年 3 月 13 日
Great!
That was it. mexCallMATLAB was probably hiding it, and adding it manually solved the problem.
Thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStandalone Applications についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by