Linking

From Linuxintro
Revision as of 18:11, 31 December 2010 by imported>ThorstenStaerk

To build an executable program from source code, you have to compile and link it. Compilation is translating the source code into machine language, linking is adding functionality from libraries like drawing a circle, writing or printing text. "Adding functionality from libraries to an executable program" can mean that you add the code from the library to your program or that you call a function from your program. Adding the code is called static linking, calling a function from a library is called dynamic linking.

Advantages of dynamic linking are:

  • your program is separate from the libraries. If libraries need to be fixed, there is no need to touch your files
  • your program will require less space in memory if the libraries are already loaded for other programs
  • your program will require less space on disk which is typically relevant when programming for embedded devices like mobile phones etc.

Advantages of static linking are:

  • your program's behavior does not change, there is no possibility a library gets "fixed" and your program does not work any longer
  • your program can be deployed into various environments, like different Linux distributions, and will "just work"
  • you can be sure about your program's behavior - you will need to test only once, not for every possible library version

See