doubleE
doubleE

Reputation: 1073

What does resolving reference mean in Linker/Compiler?

I don't understand fully why we need a linker. Compiler first turn the highlevel code to assembly, then this assembly code is translated to machine code. Everything we want(except which address to load this code) is present. Why needing a separate Linker module? Assume my program is

printf("Hello Basic Question!");

this C code translates to bunch of assembly instructions. I don't understand when we say Linker resolves reference to printf. Can you elaborate please? Does it mean in some library there is a mapping between printf and assembly instructions and linker simply pull that mapping out and replaces the printf with that?

Upvotes: 2

Views: 710

Answers (1)

Frankie_C
Frankie_C

Reputation: 4877

printf is a function that is not in your code, but in an object library. printf calls some kernel functions to output your message. The linker resolves references, extract object modules from libraries and add them to your executable. It also resolves references to call kernel functions and produce all data structures used by the OS loader module to allocate memory, load and execute your code.

Upvotes: 3

Related Questions