14.2. Introducing Linking

As previously mentioned, function libraries can be linked or incorporated into applications when required. Libraries are linked using a tool called a linker. It takes objects created by a compiler and puts them together into a single executable file. There are two types of linking: static and dynamic. Static linking occurs at design time, when you create the application. Dynamic linking occurs at runtime.

14.2.1. Static Linking

Most programming languages provide the capability to access some operating system functions. They also usually enable 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, the 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 14-1 illustrates how static linking works.

Figure 14.1. Figure 14-1

Although newer compilers enable you to copy individual functions, older ones typically copied the entire module to the application when linking a library. This meant that all the library's functions were merged into ...

Get Access™ 2007 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.