←back to thread

383 points hkalbasi | 2 comments | | HN request time: 0.425s | source
1. juujian ◴[] No.42818212[source]
Is it too late to ask what a linker is?
replies(1): >>42818401 #
2. nappy-doo ◴[] No.42818401[source]
I'll ELI5:

Compilers take the code the programmer writes, and turns it into things called object files. Object files are close to executable by the target processor, but not completely. There are little places where the code needs to be rewritten to handle access to subroutines, access operating system functionality, and other things.

A linker combines all these object files, does the necessary rewriting, and generates something that the operating system can use.

It's the final step in building an executable.

--

More complicatedly: a linker is a little Turing machine that runs over the object files. Some can do complicated things like rewriting code, or optimizing across function calls. But, fundamentally, they plop all the object files together and follow little scripts (or rewrites) that clean up the places the compiler couldn't properly insert instructions because the compiler doesn't know the final layout of the program.