source: https://www.thedailybeast.com/real-gabinete-portugues-de-leitura-rio-de-janeiro-the-worlds-most-beautiful-libraries

Static libraries vs dynamic libraries

Why do we use libraries?

What’s a static library.

A static library is a collection of object files that are linked into the program during the compilation and are not relevant during runtime, these libraries are include into the executable file so the bigger the library the bigger the file. A static library resides into the executable in form of a binary code so it can only be used by this program.

What’s a dynamic library.

A dynamic library is a collection of object files that are linked into the program during runtime but not in the compilation process, during the compilation the libraries are just referenced in the executable by its memory direction. These libraries are stored in the memory and can be shared for multiple programs.

How to create them.

Static libraries

  1. Compile the object files of the library
  1. compile the object files using:
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH 

Advantages and drawback

Advantages

  • The speed of execution is faster because all the libraries are included in the executable in binary form.
  • there is no compatible issues due to all the code is contained on the executable
  • The executable have less space
  • Updates of the library no need a recompilation of the executable
  • One library can be shared for multiple programs
  • Linking load time will be reduced if the library is already present in memory
  • Every program must contain its own library and bigger libraries makes bigger executables
  • Updates on the library requires a recompile of the executable
  • Slower execution time
  • If the library is removed or the path is not correct our executable will not execute correctly

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store