Compiling functions that loads an external dll library in 64bits (thunk file problems)

12 views (last 30 days)
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).
Thanks

Answers (3)

Tejas M U
Tejas M U on 3 Jul 2014
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.
  1 Comment
Mathieu
Mathieu on 4 Jul 2014
Edited: Mathieu on 4 Jul 2014
Hi, my application is running when compiled in 32bits and also running when not compiled.
In 64 bits the error which I can't solve is a call to thunkoadfile.
how do I get a thunk file ? As mentioned above, matlab generates a thunk*.dll at the same time as the prototype function but I don't know what I am supposed to do with it.

Sign in to comment.


Image Analyst
Image Analyst on 3 Jul 2014
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.
  1 Comment
Mathieu
Mathieu on 4 Jul 2014
Thanks.
I have a prototype file (.m) as well as a dll both generated by the loadlibrary function of matlab.
I'm not putting the file as an mcc argument: I'll try that. I was trying to deploy with the deploy tool. I also did mcc calls but without passing the dll as an argument.
Oddly enough there is no documentation on that on the mcc page.

Sign in to comment.


Ofek
Ofek on 15 Jul 2016
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 Comment
David Ahrens
David Ahrens on 26 Feb 2021
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

Sign in to comment.

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!