Function 'loadlibrary' is not supported for standalone code generation. Seeking alternative options.

7 次查看(过去 30 天)
Hi,
I am using loadlibrary() to call some functions from a C++ .dll file so that I can develop my application in MATLAB.
However, when I try to generate standalone code using MATLAB Coder, I get the following error:
>> coder -build CodeApp.prj
??? The function 'loadlibrary' is not supported
for standalone code generation. See the
documentation for coder.extrinsic to learn how
you can use this function in simulation.
It appears that loadlibrary is not supported for code generation. Does anyone know of other ways where I can include the .dll file?
(I could compile my application using MATLAB Compiler, but that would require MCR, which isn't what I need.)
Any help would be very much appreciated.

采纳的回答

Mike Hosea
Mike Hosea 2011-4-22
Unfortunately, I don't have a lot of experience trying to do this kind of thing, so I apologize in advance if there are helpful details that I ought to mention but don't happen to know. What I do know that the intended tool for code generation would be coder.ceval. Now, coder.ceval doesn't work in MATLAB, but you can use coder.target in a judicious way so that your application will still run in MATLAB while you're developing it and will also generate code. Something like
runningInMATLAB = isempty(coder.target);
if runningInMATLAB
loadlibrary(...)
end
...
if runningInMATLAB
% Use calllib here
else
% Use coder.ceval here to call the same function
end
...
if runningInMATLAB
unloadlibrary(...);
end
HTH -- Mike
  2 个评论
Yu Ang Tan
Yu Ang Tan 2011-4-25
Hi Mike
Wow, you're being too modest. Yes, coder.ceval worked for me, as long as I have included the library in the coder dialog box.
There's a small pain though, as MATLAB changes splits up my new line (\n) to separate characters : '\' and 'n'.
Clearly, there's a better way to do this, but for now I'll just have to call a function to print a new line. (laughs)
Thanks once again.
Kaustubha Govind
Kaustubha Govind 2011-4-25
Yu: When you say MATLAB splits up your "\n" did you mean:
>> disp('test\nprint')
test\nprint
If so, you may want to use sprintf:
>> disp(sprintf('test\nprint'))
test
print

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by