What is a Library
A library is
- Useful code that has been compiled already
- Hence saves having to recompile that same bit of code
- Can be used (linked to) in other programs or by other people
- DRY (don't repeat yourself) principles - don't need to reinvent the wheel for universal functions. Eg you don't want to have to program how to draw a window with the maximize, minimize, close buttons for every program you make, so instead you can link to the windows libraries.
Static Library
- Stored in archive .a files
- Machine code for external functions is copied directly to your final executable
- Makes your executable larger
- (makes it easier to give to friends, they don't need library installed?)
- Stored as shared object .so files
- Only a table of functions used is stored in your exe
- when your exe starts, it loads up the linked libraries into memory (dynamic linking)
- Final exe is smaller
- OS will load the linked library into virtual memory, this can be used by multiple programs at once - saving memory usage
- Can update library without recompiling code (unless the APIs change)