Why do I receive errors when trying to compile LOADLIBRARY or run an application that uses LOADLIBRARY with MATLAB Compiler 4.0 (R14)?

6 views (last 30 days)
I am running into errors when attempting to compile my code that uses the LOADLIBRARY function. There are several situations I have seen:
1. When compiling the following code:
function [a,b]=testloadlibrary
try
library = [matlabroot, '\bin\win32\libmx.dll'];
header = [matlabroot, '\extern\include\matrix.h'];
alias = 'libmx';
loadlibrary(library, header, 'alias', alias);
libmethods(alias);
unloadlibrary(alias);
catch
disp(lasterr);
end
I receive the following error:
Output argument 'notfound' was not assigned during call to 'loadlibrary'.
2. I am able to compile the above code successfully, but at runtime I get one of the following two error messages:
Warning: Function call testloadlibcompile invokes inexact match
d:\work\testLoadLibCompile_mcr\testLoadLibCompile\testLoadLibCompile.m.
??? Error using ==> loadlibrary
Call to Perl failed. Possible error processing header file.
Output of Perl command:
Error using ==> perl
All input arguments must be valid strings.
Error in ==> testLoadLibCompile at 4
MATLAB:loadlibrary:cannotgeneratemfile
There was an error running the loader mfile. Use the mfilename option
to produce a file that you can debug and fix. Please report this
error to the MathWorks so we can improve this function.
??? Error using ==> feval
Undefined function or variable 'GHlinkTest_proto'.
Error in ==> loadtest at 6

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Nov 2011
This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information:
With MATLAB Compiler 4.0 (R14) and later, you can use MATLAB file prototypes as described below to load your library in a compiled application. Note that loading libraries using H-file headers is not supported in compiled applications.
This behavior occurs when LOADLIBRARY is compiled with the header argument as in the statement below:
loadlibrary(library, header)
In order to workaround this issue, execute the following command at the MATLAB commmand prompt:
loadlibrary(library, header, 'mfilename', 'mHeader');
... where mHeader is the name of a MATLAB file (in this case mHeader.m) that you would like to use when loading this library. This step only needs to be performed once to generate an MATLAB file for the library.
Now, in the code that is be compiled, you can call LOADLIBRARY with the following format:
loadlibrary(library, @mHeader, 'alias', alias)
With MATLAB Compiler versions 4.0.1 (R14+) and above, the generated MATLAB file mHeader.m will automatically be included in the CTF file as part of the compilation process. For versions 4.0 of the Compiler (R14) and later, include your library MATLAB file in the compilation with the '-a' option with MCC.
Note: With the MATLAB Compiler 3.0 (R13SP1) and earlier versions you cannot compile calls to LOADLIBRARY because of general restrictions and limitations of the MATLAB Compiler.
If you do not have a header file, the prototype file can be created manually. Follow the example in the documentation to generate a prototype file and modify it to suit the shared library you would like to use:
web([docroot,'/techdoc/ref/loadlibrary.html'])

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!