Compiling functions that loads an external dll library in 64bits (thunk file problems)
9 次查看(过去 30 天)
显示 更早的评论
Hi, The application that I'm trying to compile is calling the loadlibrary function. I had a series of errors and found in the documentation that I should use a prototype function, then a thunk file. I saw some generated , *thunk_pcwin64.dll exp, lib and obj files and tried to load the dll, but it is still not working ()
I did not find any documentation on how to proceed : should I only call the generated dll ? (this does not work with the uncompiled version).
Are there some example or documentation on this ? I only found http://www.mathworks.nl/help/matlab/ref/loadlibrary.html#btjpunx-1 http://www.mathworks.nl/help/matlab/matlab_external/prototype-files.html
Thanks
0 个评论
回答(3 个)
Tejas M U
2014-7-3
What is the error message? Which language is your application written in? C++ libraries need thunk files. Are you creating a library from MATLAB? If so, have you added the prototype file in the ‘additional files’ section while creating the load library? When you are using the load library in your application program, are you linking the DLL to the application?
Also, here are some limitations of loadlibrary:
1. You must have a supported C compiler and Perl must be available.
2. Do not call loadlibrary if the library is already in memory. To test this condition, call libisloaded.
3. loadlibrary does not support libraries generated by the MATLAB Compiler™ product.
4. The MATLAB Shared Library interface does not support library functions with function pointer inputs.
Image Analyst
2014-7-3
Do you have a prototype file? And are you adding the file as an mcc argument:
mcc -m yourApp.m -d 'D:\MATLAB\OutputFolder' -a cbw_prototype_file.m -a cbw64_thunk_pcwin64.dll -a 'C:\Program Files (x86)\Measurement Computing\DAQ\cbw64.dll'
It's been a while since I've figured it out so I don't remember all the details about why things are done, but you can look over my file. I had to create this and run it to make some files in order to run a DLL from Measurement Computing Corporation that talks to one of their digital I/O devices.
Ofek
2016-7-15
I know this question is old - but in hope of helping others googling their way here, let me try to fill in some details.
The question is a bit vague and if it had the exact error messages we might have been able to help more - but it does closely resemble some issues we had trying to deploy components calling loadlibrary.
The loadlibrary documentation does leave much to be desired, and some hacking had to be used to understand this apparatus better. The full (-ish) details are laid out here, but the bottom lines are:
1) The proto file contains info about calling the thunk DLL.
2) The thunk DLL is about adjusting calling conventions.
3) When the Matlab component consuming the native DLL is deployed (using matlab compiler), the loadlibrary call is made from wherever the CTF archive was extracted to – and it occasionally fails to find the thunk dll. Our solution was to intervene in the proto.m file, and have it take the thunk path from the registry.
1 个评论
David Ahrens
2021-2-26
I know this is old.
How do you get the thunk path from the registry?
using matlab 2017a,
I get the loadlibrary call responding with a warning 'Warning: The function '<funcName>' was not found in the library' for every method and in the order of the proto file.
All works fine on the machine with matlab installed. When trying to execute on the machine with MCR installed I get the problems.
Redistributing using the ctf file bundled in my installer.
Have tried to hard code the directory that the MCR runs from directly into the proto file
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!