Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Linking a C program

the process of linking library files with object program is known as linking



1) my question is that what is purpose of linking a c program why it is need

2) what is library files in above definition of linking a C program
Posted

In the Bad Old Days of computing, your program was assembled or compiled from a sequence of source files, and it was necessary to compile all of them at the same time to produce a working executable.

Computers were slow then, so with big projects this could take a long time. And we are talking days, not minutes here! So some clever chap thought to himself "What if I half compile each file and then join them together at the end?" So he did - he compiled to a form known as an Object File and then wrote another program to build all the Object files together - he called this a Linker. Now, only the files that had changed needed to be compiled again, saving a whole load of time!

Later, (but not much later) Libraries were added to the objects a linker could include as necessary, so that the relevant code was only included if it was needed.
 
Share this answer
 
Very good and genuine question.

First of all let me answer your second query :
what is library files in above definition of linking a C program
Ans : A library refers to the set of common functions that are needed by a developer for writing the programmes. e.g For doing string operations one needs strconcat, strcopy etc. These are string related functions. So these are written in string.c (just for example) so string.c is library file. In order to use this library we have to use string.h in the header of the c programme. Other examples are Math.h, Stdio.h etc.

my question is that what is purpose of linking a c program why it is need
The concept of linking can be better understood from this link[^]

Hope this helps.
All the best.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900