Week 14 Day 1 - Static vs Dynamic Linking
Today we went over the new homework assignment for the first half of class, and then moved into the last part of our discussion on CALL (Compiler / Assembler / Linker / Loader).
The homework assignment will be a hash table done in assembly. I went over the C++ version and some C++ feature y'all might not have seen before.
A library file (a .a or .so file) is just a collection of .o files put together to make them easier to distribute and manage. You can link a library in to your code like you link a .o file (like g++ main.cc foo.a), or you can use the -l flag to link a standard library in, like if you want to link in libm (math library), you can do gcc main.c -lm.
A statically linked executable will have all functions embedded into the executable. This causes the executable to explode in size (from 8k to 500k in my example today) but makes it stable. It won't run differently if the shared libraries on the system update. It can be easier to distribute this way too.
Dynamic linking (which is on by default for the standard library) means that the linker will identify the function in the standard library and write down where it is, but it defers loading it until the loader (exec()) runs.When the loader loads your program, it searches for the missing functions, and links them in then.
This has the advantage of letting parts of your program (say the standard library code you call) update independently of your program. This is usually good, but might be bad if there is an ABI break or if they introduce a bug or incompatibility. DLLs in Windows and .so files in Linux are dynamic libraries.