+ 3

What is linking in a program language?

11th Feb 2018, 6:08 PM
Kimiya Nayyeri
Kimiya Nayyeri - avatar
2 Respuestas
+ 11
Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. For instance, if you compile (but don't link) three separate files, you will have three object files created as output, each with the name <filename>.o or <filename>.obj (the extension will depend on your compiler). Each of these files contains a translation of your source code file into a machine language file -- but you can't run them yet! You need to turn them into executables your operating system can use. That's where the linker comes in.  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.  https://www.cprogramming.com/compilingandlinking.html
11th Feb 2018, 7:02 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
thank you
11th Feb 2018, 8:52 PM
Kimiya Nayyeri
Kimiya Nayyeri - avatar