{"canonical_url":"https://engineer.company/glossary/library/","content_markdown":"# Library\n\n## What it is\n\nA library is a collection of ready-made routines that a program borrows instead of writing them:\nsomeone solved a problem once, such as parsing dates, compressing files or drawing a QR code, and\npublished the solution with a set of named entry points that any program can use. The plural is\nlibraries. C libraries on Linux are often named with a lib- prefix, Windows calls the shared kind a\nDLL, and Rust programmers say crate, a word the Rust Book notes is used interchangeably with\nlibrary. Most languages also ship a standard library, the modules available in every installation\nwithout adding anything.\n\nA library is a kind of reusable code, and it is easiest to define against its neighbours. An\napplication runs on its own and has a user; a library has neither and only runs inside a program\nthat calls it. A framework is the closer comparison. With a library, your code is in charge and\ncalls it when it needs something; a framework is in charge and calls your code at the points it\ndefines. A package, finally, is the box a library ships in, with a name, a version and a list of\nwhat it needs, and the library is the code inside the box.\n\nWhat makes a library usable is its interface: the functions, types and constants it promises to\nkeep. Semantic Versioning builds its whole scheme on that promise. A project that follows it must\ndeclare a public API, and its major version goes up whenever that API changes incompatibly.\n\nThe Program Library HOWTO sorts libraries on Linux by when they join the program. A static library\nis copied into the executable when it is built. A shared library is loaded when the program starts\nand is used by every program that needs it, so it can be updated without rebuilding them. A\ndynamically loaded library is opened while the program is running, which is how plugin systems\nusually work.\n\n## Why it matters\n\nEach library a project adopts is a decision with three possible answers: take an existing one, write\nthe code in-house, or copy a small, focused piece into the repository and own it from then on, which\nis called vendoring.\n\nTaking a library is usually right. Its authors have met the edge cases, and other users have already\nfiled the bug reports. The cost comes later and is easy to miss: the library's own dependencies\narrive with it, its security advisories become yours, its release schedule sets the pace of your\nupgrades, and its licence travels into your product. A library its maintainer has abandoned stays in\nyour build until someone replaces it.\n\nWriting it yourself buys control and costs everything the library would have saved: the edge cases,\nthe tests and the maintenance, indefinitely. It is the right call when the problem is narrow and\ncentral, when the available libraries are far larger than the need, or when a project has a reason\nto keep its dependency count low.\n\nHow a library is linked matters as well. A program built with a static library carries a fixed copy,\nso a security fix in the library reaches users only when the program is rebuilt and shipped again. A\nshared library can be patched once for the whole system, at the price of the program trusting\nwhatever version the system supplies. Licensing ignores the difference: the GNU licence FAQ states\nthat a GPL-covered work linked with other modules, whether statically or dynamically, forms a\ncombined work, and the GPL's terms then cover the whole combination.\n\nFor anyone commissioning software, the practical questions are which libraries the result depends\non, under which licences, and who owns any libraries the supplier brings along.\n\n## What it looks like in practice\n\nA document generator needed a QR code pointing at each document's online version. Any of the\nexisting QR libraries would have done the job, but the project had deliberately limited itself to\ntwo runtime dependencies, a template engine and a PDF renderer, a limit chosen so the generator\nwould keep installing cleanly long after release. The answer was to\n[vendor a QR encoder in 522 lines](/portfolio/vendored-a-qr-encoder-in-522-lines/): byte-mode\nencoding, Reed-Solomon error correction over GF(256), the finder, timing and alignment patterns,\nformat and version information, and all eight mask patterns scored against the four penalty rules. A\ndecoder written separately reads every generated code back on every run and checks that it returns\nthe input. The page is careful about its claim: the encoder covers only the modes and versions those\ndocuments use, and the reason for it is the dependency budget, not a belief that it beats a mature\nlibrary.\n\nA native macOS client calls a core library through its C interface, and early on that interface was\nrepresented by a hand-written header. Calls to three functions that had since left the core\ncompiled, linked and then crashed at runtime, because the compiler and the linker had only ever seen\nthe hand-written stand-in and never the core's real declarations. The fix was\n[a parser that verifies every call site](/portfolio/wrote-a-parser-verifying-every-ffi-call/)\nagainst the real 7,308-line header and its 268 declarations, failing the build on any call or enum\nconstant the header does not declare. It checks declarations, so a function that keeps its signature\nwhile changing its meaning still passes.\n\nThe [terms](/terms/) of every engagement settle who owns what. Code written for a client becomes the\nclient's on full payment. Libraries and general-purpose tools the company wrote earlier, or wrote\nfor itself, are the exception: ownership stays with the company, and the client gets a licence to\nuse them inside the delivered work that never expires and cannot be withdrawn. Open-source code from\nthird parties stays under the licence its authors chose, and the client is told which of those\ncomponents ended up in the result.\n\n## Where it goes wrong\n\n### A routine update breaks the build\n\nA dependency moves from 2.3 to 2.4, and code that compiled yesterday fails or behaves differently.\nEither the library changed its public interface without raising its major version, or the project\nrelied on something the library never promised, such as an internal function or an undocumented\nbehaviour. Pin exact versions in a lock file, upgrade on purpose with the changelog open, and call\nonly what the library documents as public.\n\n### The program trusts a description of the library\n\nA clean build crashes the first time a feature is used. The code was compiled against headers, type\nstubs or bindings written by hand, and these drifted away from the library actually linked in.\nGenerate bindings from the library's own published interface, or check every call against it as part\nof the build, so a mismatch fails there rather than in front of a user.\n\n### One small feature drags in a large tree\n\nA single function was needed, and the library that provides it came with dozens of dependencies of\nits own, each one another set of advisories, licences and updates. Before adding a library, look at\nwhat it pulls in, not just at its own size. When the need is narrow and well specified, a small\npiece of vendored code with its own tests can be the cheaper thing to own.\n\n### The licence arrives with the code\n\nLate in a project, someone notices that a library inside a closed-source product is under a licence\nwhose terms extend to the whole combined work. Nobody checked licences when the library was added,\nand linking it dynamically changed nothing. Check the licence of every library at the moment it is\nadded, keep the list with the release, and ask suppliers for theirs.\n\n## Further reading\n\n- [Program Library HOWTO: Introduction](https://tldp.org/HOWTO/Program-Library-HOWTO/introduction.html)\n  — what a program library is on Linux, and how static, shared and dynamically loaded libraries\n  differ.\n- [The Rust Programming Language: Packages and Crates](https://doc.rust-lang.org/book/ch07-01-packages-and-crates.html)\n  — library crates versus binary crates, and how a package holds them.\n- [Semantic Versioning 2.0.0](https://semver.org/) — the version-number rules that turn a library's\n  public API into a promise.\n- [The Python Standard Library](https://docs.python.org/3/library/index.html) — a standard library\n  at full size: everything that ships with every Python installation.\n- [Frequently Asked Questions about the GNU Licenses](https://www.gnu.org/licenses/gpl-faq.html) —\n  what the GPL means for programs that link a covered library, statically or dynamically.\n\n\u003chttps://engineer.company/glossary/library/\u003e\n","date_modified":"2026-10-20T21:59:50Z","description":"What a software library is, how it differs from a framework and a package, what each dependency costs, and when writing the code yourself is the better call.","formats":{"gemtext":"https://engineer.company/glossary/library/index.gmi","gopher":"https://engineer.company/glossary/library/gophermap","html":"https://engineer.company/glossary/library/","json":"https://engineer.company/glossary/library/index.json","markdown":"https://engineer.company/glossary/library/index.md","pdf":"https://engineer.company/glossary/library/index.pdf"},"kind":"page","language":"en","title":"What is a library?","url":"https://engineer.company/glossary/library/","version":1}