dynamic link library (DLL) (original) (raw)

A dynamic link library (DLL) is a collection of small programs that larger programs can load when needed to complete specific tasks. The small program, called a DLL file, contains instructions that help the larger program handle what may not be a core function of the original program.

An example of those tasks might be communicating with a specific device, such as a printer or scanner to process a document. DLL files that support specific device operations are known as device drivers.

DLL contains bits of code and data, like classes and variables, or other resources such as images that the larger program can use.

In addition to being a generic term for dynamic link libraries, Dynamic Link Library is also the name of Microsoft's version of the shared library concept for Windows. A shared library can exist in any operating system (OS).

Computer programs are rarely written in a one file. They often are composed of multiple files that are linked together.

When a program is run, it must be compiled from its source code, which is human readable code that the programmer writes. It's turned into an executable file, which is binary code, or machine code, that the computer can read.

The computer goes through several intermediate steps for this to occur. During those steps, multiple files are linked to one. There are two types of linking -- static and dynamic -- and two types of corresponding link libraries:

diagram of executable file program compilation

Object code contains placeholder symbols that tell the operating system which libraries to link to at runtime to create the final executable file.

Static links. These are linked earlier in the process and are embedded into the executable. Static libraries are linked to the executable when the program is compiled. Dynamic libraries are linked later, either at runtime or at load time. Static libraries are not shared between programs because they are written into the individual executable.

Dynamic links. DLLs contain the files that a program links to. The libraries already are stored on the computer, external to the program that the user writes. They are called dynamic because they are not embedded in the executable -- they just link to it when needed.

An import library, which is a type of static library, replaces all placeholder symbols with actual links to the necessary DLL data in the main program at load time, pulling those functions from the DLL library. Programs provide the name of the library, and the OS creates a path to the link library. Different programs have their own language-specific calling conventions for linking to DLLs.

Because dynamic libraries are not written into the executable, the same shared library can be used by more than one program at the same time. They can also be modified without changing the entire program that is using it.

diagram of static linking vs. dynamic linking

More than one application can access a dynamic library at once, because they are not embedded with the executable at compile time. Static libraries are embedded into programs, which lead to duplicates among the multiple programs using them.

A dynamically linked program has a small bit of code that maps the DLL into virtual memory, where the program can access it at runtime or load time. With this setup, the dynamically linked program doesn't have to repeatedly access physical memory to access the library. Virtual memory links the same page of physical memory to different programs' virtual addresses -- also known as address space -- as different processes are run.

In the Windows operating systems, dynamic files have a ".dll" file extension, and static files have a ".lib" extension. DLL files may also have ".ocx" (ActiveX), ".cpl" (Control Panel) or ".drv" (driver) suffixes, depending on the DLL function.

Programs do not always need dynamic libraries. In some cases, static linking is preferable. However, some programs specify DLLs that are needed to run and will return an error message if they cannot be accessed.

What are the advantages of dynamic linking?

Dynamic linking and DLLs offer the following advantages:

What are the challenges of dynamic linking?

Some of the downsides of dynamic linking include the following:

How do you fix DLL errors?

DLL errors are common because of the volume of DLL files found on Microsoft Windows systems and how often they are used. Errors happen when an application can't find a file and cannot run without it.

Common reasons for DLL errors include:

Redownloading the DLL file is one way to fix an issue. However, this can overload memory and create a duplicate file if the original is still on the device.

A better solution involves troubleshooting the DLL problem or doing a few basic maintenance tasks, such as restarting the computer and checking the recycle bin to see if the file was accidentally deleted. If the file was deleted, but is not in the recycling bin, users can try a file recovery program.

A missing DLL error can be a sign of a computer virus or exploit, so a malware scan may be needed. A system restore from a previous backup could solve the problem by bringing the computer's OS back to its state before the DLL file was corrupted.

Microsoft also offers several DLL troubleshooting tools, such as:

Learn about other application security threats in addition to DLL hijacking and how to prevent them.

This was last updated in November 2021

Dig Deeper on IT operations and infrastructure management