SundayMonday
SundayMonday

Reputation: 19737

What does linking mean in the context of compilers?

I'm learning more about compilers. While trying to understand this Wikipedia article on LLVM I ran across the term "linking". I've seen this term before but don't truly understand it. In the context of compilers what does linking mean?

Upvotes: 2

Views: 437

Answers (2)

David Schwartz
David Schwartz

Reputation: 182779

Linking is the process of connecting all the compiled objects to each other to form the final executable. When you call a function in one piece of code, it's the job of the linker to hook the code that calls the function to the code that implements the function.

Upvotes: 2

dimme
dimme

Reputation: 4424

Source: here

"Linking refers to the creation of a single executable file from multiple object files. In this step, it is common that the linker will complain about undefined functions (commonly, main itself). During compilation, if the compiler could not find the definition for a particular function, it would just assume that the function was defined in another file. If this isn't the case, there's no way the compiler would know -- it doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look at multiple files and try to find references for the functions that weren't mentioned."

In other words: Linking connects together all your compiled libraries/binaries that depend on each-other so that execution of your program will be possible.

Upvotes: 1

Related Questions