views:

66

answers:

3

Is the Linker part of the Operating System or the Compiler/IDE?

+7  A: 

It is part of the compiler/IDE. Or to be precise, the compiler and the linker are separate programs (invoked at separate phases of building an executable), but usually the whole bunch (which includes several other executables) is referred to as a compiler, e.g. gcc.

The linker is not part of the OS, although some OSs (such as Linux) may come bundled with one (or even multiple) linker(s) as part of some compiler toolchain(s). Regardless of this, you can install and use several different compilers (which include their own linker each) on the same OS. E.g. on a Windows OS you can have both gcc and msvc installed, although gcc can't be used with the Visual Studio IDE, as it is bundled only with msvc. But AFAIK Eclipse can use either.

Update: you seem to be confused by the name similarity between the linker in the compiler toolchain and the dynamic linker of an OS.

The linker of the compiler toolchain does its job during the build process, when it needs to patch together different compilation units to form a coherent executable program. Often, the code contains calls to external libraries; these libraries can be either static or dynamic. Static libraries are basically storages of executable methods, which the linker can physically copy into an executable. Dynamic libraries contain methods which need not be copied; instead, the linker stores a sort of reference to the library method into the executable. When the executable is run, the dynamic library is loaded with the help of the OS, and the library method is then called. This is accomplished by a part of the OS which is, rather unfortunately, called the dynamic linker - however this is entirely different from the linker in the compiler toolchain, and should rather be called loader.

Dynamic libraries can be shared in memory, i.e. the same library code can be used by multiple executables in parallel (hence they are also referred to as shared libraries). Whereas code copied from static libraries is duplicated across all executables.

Péter Török
@Xaero, a linker is not part of the OS, although some OSs (such as Linux) may come bundled with one (or even multiple) linker(s) as part of some compiler toolchain(s).
Péter Török
Doesn't an OS have Dynamic Linker?
Xaero
@Xaero, you are right, it has (that term was new to me too :-) - see my update.
Péter Török
An upvote for being gentle and patient. :D thanks
Xaero
+1  A: 

The linker is part of the compiler tool chain (preprocessor -> compiler -> assembler -> linker).

Kyle Lutz
A: 

it is part of compiler usually. technically compiler and linker are different tools, but they usually come together.

Andrey
@Xaero: Linking does not need support of OS. `ld` is Linux specific. On Widnows you link your programs with a compiler suite.
doc
Windows uses Dynamic Link Libraries doesnt it?
Xaero
@Xaero: It's only a name for shared libraries on Windows. Dynamic Link Library or `DLL`. On Linux you have Shared Objects or `so`. You can build dll for windows with a variety of tools. But Windows doesn't have a linker for its own.
doc
So different IDE/Compilers may need different Linkers? :o
Xaero
@Xaero: Exactly.
doc
So doesnt it depend on the Context one is talking in? If i talk w.r.t Linking and Loading it may imply to an OS, while Linking after Compilation is completely different?
Xaero
@doc, according to Wikipedia, it has: http://en.wikipedia.org/wiki/Dynamic_linker (was a surprise to me too :-)
Péter Török
@Xaero, in practice, compilation and linking within the build process is OS-dependent too, as you are creating an executable for that specific OS + processor architecture (aka platform). The original source code may be portable between different platforms; the executable built from it is not. So the same compiler toolchain may have different implementations for different platforms (gcc is a good example).
Péter Török
@Péter Török: That's not a surprise. "Linking is often referred to as a process that is performed at compile time of the executable while a dynamic linker is in actuality a **special loader** that loads external shared libraries into a running process". Dynamic linker != linker. On Windows "dynamic linker" is accessible only through Windows API and it certainly can not build any artifact. Naming of all this stuff is quite unfortunate.
doc
@doc, fully agreed :-(
Péter Török