Libraries

Study different ways to link libraries.

Contents

Libraries typically contain functions that can be reused by different programs. Before the function can be used in your program, the library must be linked with your program.

Two ways to link

Libraries can be linked to the client program that uses them in either of the following ways:

  1. statically
  2. dynamically

Static linking

When linked statically, the library becomes part of the client’s exe file. This leads to a waste of space on the hard disk and memory, as different copies of the library code gets repeated.

Dynamic linking

This waste of space, however, does not happen if we link the libraries dynamically. A dynamic library remains separate from the client program and can be shared anywhere. There are two ways to link a library dynamically:

  1. Load-time dynamic linking
  2. Run-time dynamic linking

Get hands-on with 1200+ tech skills courses.