3

So I am given a .lib and .h and need to make it callable from Matlab. I have been researching various ways to do this and it seems using Matlab's loadlibrary is the best way to go.

Therefore, I need to create a .dll from this .lib and its .h. I do not have access to the implementation of the .lib but do have access to the .h. According to this post: Converting static link library to dynamic dll it says creating a .def is the best route. However, I have had issues finding resources on how to create a .def file and then use the .def file to create the .dll.

Can anyone offer any advice on how to do this?

Thanks

54321
  • 99
  • 1
  • 8
  • The link you provided shows an example .def file and how to consume both the .def and .lib using `link.exe`. What else do you need to know? – Michael Gunter Jun 29 '17 at 16:55
  • It does not provide much input on the creation of the .def file, which is what I am asking in this post. – 54321 Jun 29 '17 at 17:40
  • It's just a text file. The documentation for all of the capabilities is linked to from the link you provided. Please read it, and if you have any specific questions, you'll get a specific response. – Michael Gunter Jun 29 '17 at 17:42
  • So would my .def file look like this: – 54321 Jun 30 '17 at 19:00
  • LIBRARY EXPORTS add subtract multiply divide (names of rest of functions in .lib file) – 54321 Jun 30 '17 at 19:05
  • ^the spacing did not go through but it is the same as shown in the other post that I have linked – 54321 Jun 30 '17 at 19:05
  • 1
    Yep, that's pretty much it. The names of the exports are indented from the EXPORTS header. BUT... have you read the bit about calling conventions? Matlab almost certainly expects the exported functions to be stdcall in the C++ code (that is, decorated with the __stdcall keyword or a macro that uses it like WINAPI). This is NOT the default. The developer of the .lib must explicitly do this. If they did not you will have to write your own C++ to wrap each function in a function that is __stdcall. The link you provide has all that information. – Michael Gunter Jun 30 '17 at 19:14
  • So I can't figure out where to find this .def file. I can't open the .lib file (it cant be changed) and there is no way to navigate to the properties section from the .h. Side note: How would I execute that link command noted in the other post? Do I just navigate the library in my terminal and essentially copy and paste the command? Thanks again for your help, much appreciated. – 54321 Jun 30 '17 at 20:18

0 Answers0