Search code examples
cdlldllimportdllexport

Importing DLL using a module definition file (.def)


I want to create and ship a windows C library. I've read there are two ways to do it, one using __declspec(dllexport) and __declspec(dllimport) in the header files and one using a module definition file (link). I don't want to modify the header files so I've opted for the second one and created the library, which I've confirmed it exports the required symbols.

Now, when I ship it:

  1. do the header files still need to have __declspec(dllimport) in front of every exported function so that clients can use it?
  2. do I need to ship the module definition file along with the dll, or will the .lib file suffice?

I've of course tested both with a toy example and I believe the answers to both my questions are No, but I'd like to confirm that with an experienced developer before I ship anything out.

I've found this article but it's badly written and I don't make any sense out of it.


Solution

  • You can just give your clients the .h file(s), the .lib import library, and the .dll file itself. They don't need the .def file.

    If I recall, the declspec import thing allows for a minor optimization by the linker. Something about the import table. I'll look that up later and update the answer if I can find it.