What is a linker for?

6

Some languages use a linker or Wikitravel as it is also called. What is its function and relationship to the compiler?

Why do some languages do not have a linker ?

    
asked by Maniero 21.03.2017 в 16:01
source

1 answer

7

linker is a utility that is often complementary to the compiler . It takes binary code generated by the compiler and joins everything, hence the name, into an executable. The executable can be something for direct calling or for dynamic linking (DLL).

Eventually it can generate a library with several binary codes and that can be used later to generate an executable. In these cases the library needs to be specified to call together. Often the beginner programmer does not understand why he used a #include but gives an error that he did not find a symbol (function, global variable, types, etc.). It is not a problem in the code, but in linking , there was a lack of specifying where to get this symbol, either in the library or in another binary generated separately in another compilation process.

It is common for the compiler to generate a compilation unit, in some contexts called object code. This drive can contain multiple sources. The linker joins these units, so everything in it will be placed in the executable, even if it will not be used in the application. In languages that have classes the compilation unit can include the whole class, or a group of classes.

It understands how to generate the executable format for each platform, and can do some optimizations that are only possible when all code is together. In general it does a relocation of internal addresses when it brings everything together.

Languages that have a bytecode or are interpreted do not have linker since they do not generate binary code. Some of these languages have a JITter that will generate the binary code all together.

It has utility that brings together the compiler and the linker , so it may look like there is no binary linker, but it does soon after compilation.

answered by 21.03.2017 / 16:01
source