Dynamic and Static Linking

When creating a piece of software you will most often end up with more than one file. The concept of linking deals with how those files are put together to create the final output file that can run on a machine. There are two ways to create the final output, and that is to compact everything into a single file, and then there is having multiple files that are added together at a later point.

Dynamic linking is when the output files stay separate and they are only put together at a later point. When doing dynamic linking only the names of the external libraries you want to use are put in your output file. If you have ever created software using C# you know that you get a whole set of DLL files when  you build your solution. DLL stands for Dynamic-link library and is an example of dynamic linking. When the program runs it loads in the code that it needs from the DLL files. Since you have multiple files, that also means that your code will not work if any of the files are missing.

Static linking on the other hand takes care of putting together the files at the start. It produces a single output file that contains everything that is needed to run that program. 

When using static linking all the code that is needed to run the program is present, which usually makes the file larger, but it is also faster. If you have many different programs that need to use the same functionality you might also be able to save space using dynamic linking, having the programs use the same file.

When using static linking the code is more coupled, i.e. if you need to change one part of the code you have to redeploy everything. If you were to use dynamic linking you could just redeploy the relevant files. That being said, it might be better to redeploy all the files as part of a release package regardless of how many files are actually updated.

In conclusion, dynamic and static linking are both ways to produce files that can run on a machine. Static linking puts everything into one file, while dynamic creates separate files and loads them in at a later point when you run the program.