After we are done writing a program, there is still work to be done in order to get that program in a state which our computer can execute. We must compile our code into a form the computer can understand. From this point, the final two steps necessary to run our program are linking and loading.

Most programs, but particularly larger ones, have a long list of dependencies. At execution time, our computer needs to have instructions it can comprehend not only for our program but for all of the programs ours depends on. The linker’s job is to connect our program with these dependencies. The linker outputs a file called an executable which is what the computer will actually use to run our program.

When we run that executable, the first step to execute our program is called loading. The loader takes information from the executable file and loads the information necessary to run the process into main memory.

It is important to understand that both linking and loading can occur either statically or dynamically.

If a program is linked statically, the entirety of the dependencies necessary to run the program are linked when an executable is created. Conversely, if a program is linked dynamically, the linking takes place at runtime which gives our OS the opportunity to see whether some dependencies already exist in memory before linking with them again.

On the loading side, if a program is statically loaded, then the entirety of the program and its dependencies are loaded into memory at execution time. With dynamic loading, the OS only loads the parts of the program that are needed at a given time.

The result is that dynamic linking and loading tend to be much more efficient with memory. However, the tradeoff is speed. Statically linked/loaded programs tend to execute faster because there is no back and forth of fetching dependencies once the program is running.


Click Next when you’re ready to move on to the next exercise.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?