Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to distribute a header file and a lib file with a DLL?

I'm updating a DLL for a customer and, due to corporate politics - among other things - my company has decided to no longer share source code with the customer.

Previously. I assume they had all the source and imported it as a VC++6 project. Now they will have to link to the pre-compiled DLL. I would imagine, at minimum, that I'll need to distribute the *.lib file with the DLL so that DLL entry-points can be defined. However, do I also need to distribute the header file?

If I can get away with not distributing it, how would the customer go about importing the DLL into their code?

like image 895
audiFanatic Avatar asked May 17 '16 17:05

audiFanatic


2 Answers

Yes, you will need to distribute the header along with your .lib and .dll

Why ?

At least two reasons:

  • because C++ needs to know the return type and arguments of the functions in the library (roughly said, most compilers use name mangling, to map the C++ function signature to the library entry point).
  • because if your library uses classes, the C++ compiler needs to know their layout to generate code in you the library client (e.g. how many bytes to put on the stack for parameter passing).

Additional note: If you're asking this question because you want to hide implementation details from the headers, you could consider the pimpl idiom. But this would require some refactoring of your code and could also have some consequences in terms of performance, so consider it carefully

like image 114
Christophe Avatar answered Oct 26 '22 02:10

Christophe


However, do I also need to distribute the header file?

Yes. Otherwise, your customers will have to manually declare the functions themselves before they can use it. As you can imagine, that will be very error prone and a debugging nightmare.

like image 40
R Sahu Avatar answered Oct 26 '22 01:10

R Sahu