In: Computer Science
Compilers and Assemblers translate each source file individually to generate object code files. Hence the object files need to be linked together before they can be executed. Theoretically, however, it is possible to skip the linking step and directly have compilers generate the final executable file. What would be the downside of taking the latter approach
Linking means creation of single executable file from combining different object files that are translated by the compiler . Yes , in theory it is possible to compile the object files without linking them but there are problems in following this approach and that is explained below
Following is the downside or disadvantage s of using the latter approach i.e compiling without linking :
=> Suppose you wrote a very big program with lots of functions they will all be translated as different object files and if you don't use any linker or you skip the linking step . During compilation , if the compiler could not find the definition of particular function it would simply assume that the function was defined in another file ,if that is not the case (not defined in other file also ) then there is no way the compiler would know , compiler dosen't look into more than one file at a time
=>. Then after compiling the code will not work and there will be no error messages because the compiler don't even know what went wrong . You will have to look into hundered lines of code to find error .
=>. The linker dosen't do that linker look for more than one file at a time and try to find the reference for that from function or any other symbol if it doesn't find any reference to the unmentioned function it will simply show error .
=> Compiler errors are usually syntavtic in nature : missing semicolon ,extra paranthesis and all that . While the Linker errors are more like missing or multiple definitions , without the linker you will have hard time finding these errors which will be very time consuming .