Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between a compiler and a linker?

What is the difference between a compiler and a linker in C?

like image 367
smruti Avatar asked Sep 30 '10 14:09

smruti


People also ask

What is difference between compiling and linking?

Compiling - The modified source code is compiled into binary object code. This code is not yet executable. Linking - The object code is combined with required supporting code to make an executable program. This step typically involves adding in any libraries that are required.

What is the difference between compiler linker and loader?

In brief, the difference between linker loader and compiler is that a linker combines one or more object files generated by the compiler to a single executable file and a loader places the programs into memory and prepares them for execution while a compiler converts the source code into object code.

What is compiler and linker in C++?

Compilation: the compiler takes the pre-processor's output and produces an object file from it. Linking: the linker takes the object files produced by the compiler and produces either a library or an executable file.

What is the difference between a compiler and a linker state the output file created by both?

A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.


1 Answers

The compiler converts code written in a human-readable programming language into a machine code representation which is understood by your processor. This step creates object files.

Once this step is done by the compiler, another step is needed to create a working executable that can be invoked and run, that is, associate the function calls (for example) that your compiled code needs to invoke in order to work. For example, your code could call sprintf, which is a routine in the C standard library. Your code has nothing that does the actual service provided by sprintf, it just reports that it must be called, but the actual code resides somewhere in the common C library. To perform this (and many others) linkages, the linker must be invoked. After linking, you obtain the actual executable that can run.

like image 130
Stefano Borini Avatar answered Oct 02 '22 15:10

Stefano Borini