Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Dynamic-link library works

I was thinking: when I produce a DLL with Visual Studio (C++) it generates

  • a .dll file
  • a .lib file

And I have a .h file

So, why not developing directly a static .lib library?
For example, why Office doesn't have .lib files?

And, in the future, if I change the DLL, will I have to send to all the machines also the new .lib file and .h file?

like image 455
LppEdd Avatar asked Jan 14 '23 02:01

LppEdd


2 Answers

The .h and .lib is only for developers. Whoever writes a program to use the DLL.

Those who just execute the application need only the .DLL.

So if you release a new version, you send DLL to users and the triplet to developers. Unless you changed the public interface (the exports), the old clients will be happy to use the updated DLL without any work.

If you instead build a static .lib, every client must rebuild his binaries.

like image 149
Balog Pal Avatar answered Jan 16 '23 17:01

Balog Pal


The .lib file and the header file is the static part of your dynamic library.
You need the .lib and header file in order to compile and link a program so that it uses your library.

So why not use a static library?
There are multiple reasons. One would be that if you use a static library every change of your library causes a recompile of your program. Another that the size of your program will increase. And some more.

So for your second question the lib file are useless for a user of your program. In case of office. As long as you don't have the sources and a compiler the lib files will not help.

For your last question. The answer is also simple. No you don't need to distribute the .lib files. You can replace the dll files with new versions as long as the interface stays the same.

like image 20
mkaes Avatar answered Jan 16 '23 19:01

mkaes