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:
- 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.
- 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:
- The executable file is smaller, because it does
not include the contents of the library.
- Many applications can share the same DLL by
linking to a single loaded copy at run time.
- When you modify the executable module, it may not
be necessary to rebuild every DLL it uses.
- You can often replace a DLL with a new version
without having to rebuild the entire application.
- 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.
- Will your library be linked statically or dynamically
with the modules that use the library?
Choose the version of the run-time library that provides
the correct run-time environment. A static library may be
linked with either the statically or dynamically linked
version of the VisualAge C++ run-time library. A DLL should
be linked with the dynamically linked version of the
VisualAge C++ runtime library. If your DLL is linked with
the static run-time library, it contains its own run-time
environment and applications that use your DLL may
acquire more than one run-time environment from different
modules. Avoid building applications that have multiple
run-time environments.
- Must your library support multithreaded applications?
If you library will be used only by single threaded
applications, you can improve performance by linking to
the single threaded version of the VisualAge C++ run-time
library. Otherwise, you must link to the multithreaded
run-time library. Treat all applications that use the IBM
Open Class library as multithreaded and link them with
the multithreaded version of the VisualAge C++ run-time
library.
- Will your library be used in applications that require a
run-time environment?
If you are building a library that will be used only
subsystems, link to the subsystem version 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