ArticleslgStudy

computer science

Dynamic library

Dynamic library is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Dynamic library rather than just read about it. In short: A dynamic library is a library that contains functions and data that can be used by a computer program at run-time as loaded from a file separate from the program executable. Dynamic linking or late binding allows for using a dynamic library by linking program library references with the associated objects in the library either at load-time or run-time.

Key takeaways

  • Dynamic library belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Dynamic library to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Dynamic library from memory before moving on to harder problems.

Reference excerpt

A dynamic library is a library that contains functions and data that can be used by a computer program at run-time as loaded from a file separate from the program executable. Dynamic linking or late binding allows for using a dynamic library by linking program library references with the associated objects in the library either at load-time or run-time. At program build-time, the linker records what library objects the program uses. When the program is run, a dynamic linker or linking loader associates program library references with the associated objects in the library. A dynamic library can be linked at build-time to a stub for each library resource that is resolved at run-time. Alternatively, a dynamic library can be loaded without linking to stubs. Most modern operating systems use the same format for both a dynamic library and an executable which affords two main advantages: it necessitates only one loader, and it allows an executable file to be used as a shared library. Examples of file formats use for both dynamic library and executable files include ELF, Mach-O, and PE. A dynamic library is called by different names in different contexts. In Windows and OS/2 the technology is called dynamic-link library. In Unix-like user space, it's called dynamic shared object (DSO), or usually just shared object (SO). In Linux kernel it's called loadable kernel module (LKM). In OpenVMS, it's called shareable image. As an alternative to dynamic linking, a static library is included into the program executable so that the library is not required at run-time.

Dynamic loading Dynamic loading is the process of loading a dynamic library at run-time and also unloading a library. A load can be initiated implicitly or explicitly by a program. An implicit request occurs if the program is configured to automatically load the dynamic library and this is setup at link-time. Explicit requests are made by a program via operating system API calls. For instance, Windows provides LoadLibrary, LoadLibraryEx, FreeLibrary and GetProcAddress. POSIX-based systems, including most UNIX and UNIX-like systems, use dlopen, dlclose and dlsym. A dynamic loader locates a dynamic library on request and implementation varies. Some loaders depend on the executable storing a full path to the library. Any change to the library name or location results in a run-time failure. More commonly, the library name without path information is stored in the executable, and the loader applies a search algorithm to find the file. If a dynamic library on which a program depends is unavailable (deleted, moved, renamed) or replaced with an incompatible version, the executable will fail at run-time. This is called dependency hell and on Windows DLL hell. Issues can be minimized by naming library files with a version number and by following versioning rules that require changing the version when an incompatible change is made.

Windows For a custom DLL Windows checks the directory where it loaded the program; directories configured via SetDllDirectory(); the System32, System, and Windows directories; then the current working directory; and finally the directories specified by the PATH environment variable. Applications written for the .NET Framework (since 2002), also check the Global Assembly Cache as the primary store of shared DLL files to remove the issue of DLL hell. Originally, for COM, Windows would only query the registry to locate a DLL that provides an object class. Later, Windows allowed for loading from a DLL file co-located with the program executable. To address "DLL hell", Windows applications are typically installed with private DLL files and the system prevents replacement of shared system DLLs with earlier versions.

OpenStep OpenStep used a more flexible system, collecting a list of libraries from a number of known locations (similar to the PATH concept) when the system first starts. Moving libraries around causes no problems at all, although users incur a time cost when first starting the system.

Unix-like systems Most Unix-like systems have a "search path" specifying file-system directories in which to look for dynamic libraries. Some systems specify the default path in a configuration file, others hard-code it into the dynamic loader. Some executable file formats can specify additional directories in which to search for libraries for a particular program. This can usually be overridden with an environment variable, although it is disabled for setuid and setgid programs, so that a user can't force such a program to run arbitrary code with root permissions. Developers of libraries are encouraged to place their dynamic libraries in places in the default search path. On the downside, this can make installation of new libraries problematic, and these "known" locations quickly become home to an increasing number of library files, making management more complex.

Prebinding As an optimization, systems can compute the likely load address for each dynamic library on the system to minimize load-time when the library is needed. This optimization is known as prebinding and prelinking on macOS and Linux, respectively. IBM z/VM uses a similar technique, called Discontinuous Saved Segments (DCSS). Disadvantages of this technique include the time required to compute the addresses each time a dynamic library changes, the inability to use address space layout randomization, and the requirement of sufficient virtual address space for use.

History Dynamic linking was originally developed for the Multics operating system, starting in 1964, and the MTS (Michigan Terminal System), built in the late 1960s.

Notes

References

Sources Levine, J.R. (2000). Linkers and Loaders. Operating Systems Series. Elsevier Science. ISBN 978-1-55860-496-4. Retrieved 2025-02-02.

Worked examples

Example 1 — a first encounter with Dynamic library

Start with the simplest possible case. Write down what Dynamic library claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Dynamic library before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Dynamic library ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Dynamic library

In research
Dynamic library appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Dynamic library in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Dynamic library is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer libraries, Operating system technology, so understanding it makes those chapters shorter.
In everyday life
Look for Dynamic library outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Dynamic library” →

How to study Dynamic library in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Dynamic library means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Dynamic library out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Dynamic library in simple terms?

A dynamic library is a library that contains functions and data that can be used by a computer program at run-time as loaded from a file separate from the program executable. Dynamic linking or late binding allows for using a dynamic library by linking program library references with the associated…

Why does Dynamic library matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Dynamic library?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Dynamic library.

Tags

  • Computer libraries
  • Operating system technology

Keep exploring