Static and Dynamic Link Libraries (OS/2, Windows)

Libraries are collections of linkable items that are packaged into a single file. The linker combines libraries with other linkable files, called object modules, to create new libraries or executable programs. Often, libraries contain compiled code and data that you can use in new applications that you are developing. A number of libraries are included in VisualAge C++. These include the run-time library, the IBM Open Class Library, and the C++ Standard Library.

You can build and use the following three kinds of libraries:

  1. Static Libraries
    Static linking occurs at link time. A Static library must have the file extension .lib. The linker includes code only for symbols in the library that are referenced by the target module being built. Every module that uses a function from a static library contains an independent copy of the function. For example, if five applications perform file or console I/O, the the fairly large body of code from the run-time library that supports such I/O is included in the five different executable files and stored five times in your disk space. When you build an executable file that links statically to all the libraries it uses, the program produced does not require the presence of any other code on the target machine to run.
  2. Dynamic Link Libraries (DLLs)
    Dynamic linking occurs at run time. A dynamic link library must have the extension .dll and a copy must reside on every machine on which the application will run. Executable modules load the library when they need it and link dynamically to functions and data items as they use them. DLLs have the following advantages for application developers:
  3. Import Libraries
    Import libraries are used by the linker to resolve references to symbols that are in DLLs. Usually, you have one import library for each DLL and the import library has the same base file name as the DLL. Like static libraries, import libraries must have the file extension .lib. You specify an import library as a source for a build in the same way that you specify a static library.

How you should build your library depends on how other modules will use it. The answers to the following questions can help you decide whether to link your library with the dynamic or static and single threaded or multithreaded versions of the run-time library.



Configuration Files
Run-Time Library Environments
Multithreaded Programs
Maintaining Libraries
Introduction to the Open Class Library
Subsystems


Build
Choose Your Run-Time Library
Build Static Libraries
Build Dynamic Link Libraries
Build Resource Dynamic Link Libraries
Build with Existing Object Files and Libraries