Francesco
Francesco

Reputation: 68

Why are DLLs bundled with programs instead of being globalised?

To my understanding, DLLs "Dynamic Link Libraries" are meant to be shared by many different programs, as opposite of statically linked libraries, which naturally don't appear as single files but rather go "inside" the final executable.

If this is true, why are DLLs (even the most common ones, such as the Microsoft VC++ Runtime Library) bundled with programs and not contained in a known system folder? Or, in the case that such libraries are not useful outside the program context, why aren't they linked statically?

As far as I know, this doesn't happen on Unix-like systems, where I've always encountered self-contained programs that refer to shared libraries in the manner that I have just described and that feels like an actually "correct way" to use dynamic linking.

Upvotes: 0

Views: 136

Answers (1)

Employed Russian
Employed Russian

Reputation: 213746

DLLs "Dynamic Link Libraries" are meant to be shared by many different programs

Originally, that was ~sole purpose of DLLs.

But they have evolved to serve a second purpose: representing a self-contained unit of code and data with a defined interface. In this aspect, they are very different from UNIX shared libraries: DLLs do not allow symbol interposition (without significant effort).

why are DLLs (even the most common ones, such as the Microsoft VC++ Runtime Library) bundled with programs and not contained in a known system folder?

They used to be. And this used to be the primary cause of the DLL hell.

Then Microsoft decided that disk space (and download bandwidth) became so cheap, it's easier to just ship the set of DLLs that the program was tested against with the program itself, and not worry too much about backward and forward compatibility.

in the case that such libraries are not useful outside the program context, why aren't they linked statically?

Because the program and the DLL are produced by unrelated entities, independently.

You might ask: why doesn't the DLL provider simply supply an archive library? But an archive library is distinctly not self-contained -- linking against such library requires that you use matching compiler and all the headers, which is much harder to do safely.

Upvotes: 0

Related Questions