Static Linking

Most programming languages provide the capability to access some operating system functions. They usually also allow you to create and store your own custom functions which you can compile into library (*.lib) files, and then merge into your applications.

When an executable program is compiled, a Linker scans the application for references to external functions and libraries, and then copies them into the final executable, thereby linking them to your application. This is called static linking, because the addresses your program uses to access these functions are fixed into the executable and remain unchanged (static) when the program runs. Figure 13-1 shows how static linking works.

The entire module is copied into the application

External library

Module 1

Function 10 Function 2()

Module 1

Function 10 Function 2()

Figure 13-1

Although newer compilers allow you to copy individual functions, older ones typically copied the entire module to the application when linking each library. This meant that all the library's functions were merged into the executable, regardless of whether they were needed or not.

Of course, copying the entire module to the application increased the resulting file size. While the size increase was usually small, it started to actually mean something if there were 20 executables, each containing a copy of the same library. In a multitasking environment like Windows, all 20 programs could conceivably be running simultaneously, so it would use up a great deal of memory at any one time.

Figure 13-1

0 0

Post a comment