Build Dynamic Link Libraries (OS/2, Windows)
In general, building dynamic link libraries is a simpler
process than it was in earlier versions of VisualAge C++ and predecessor products.
To build a DLL, follow these steps:
- Prepare your source files.
You can build a DLL from the same code that you
use to build an executable file, except that you should
not include a main function. There are no special coding
requirements, unless you choose to do one or more of the
following:
- You can add pragmas or keywords to your source
code to export symbols when you declare them. If
you do this for every data item, function, and
class that must be visible outside the DLL, you
can avoid having to export symbols at the build
stage.
- You can write your own function to initialize the
DLL when it is loaded and clean up when the DLL
terminates.
- If your DLL calls the signal
function and has a different run-time environment
from the executable module that uses the DLL,
apply #pragma
handler to every entry point in the DLL. Do
this to ensure that operating system exceptions
are always handled correctly.
- Export symbols so other modules can access them.
Make sure you export every symbol that may be
used by any module that links to your DLL. Otherwise the
linker may not be able to satisfy references to classes,
functions, or data in your DLL when you try to link with
other modules. You can export symbols explicitly in your
source code or with build options in the configuration
file.
- Specify a .dll file as the target of the build.
In your configuration file, make sure the target
is the file to hold your DLL and that its extension is
.dll.
- Build
Set build options if you want to override
default actions of the compiler, linker or other
processes that make up the build. There are no special
build options to set, except possibly link options to
export symbols. Consider carefully which version of the
run-time library to use. The build process creates your
DLL from all input files you specify as sources.
The build automatically creates an import library with the
same name as the dynamic link library and with the extension
.lib.
Here is an excerpt from a configuration file that builds a DLL
in a file named pets.dll and builds an import library in a file
named pets.lib from source files named cats.cpp and dogs.cpp.
option tame = link(linkWithSharedLib), link(exportAll)
option tame /* ... more options ... */ {
target "pets.dll" {
source "cats.cpp"
source "dogs.cpp"
}
}
The import library is placed in the same directory as the DLL.
You can move the import library to another directory after the
build or during the build by including a run directive like the
following in your configuration file:
run after "move pets.lib D:\mylibs\pets.lib"

Static and Dynamic
Link Libraries
Configuration
Files
Run-Time
Library Environments
Signal and
Exception Handlers in DLLs

Initialize and Terminate Your DLL
Environment
Export Symbols from a DLL
Choose Your Run-Time Library
Build Modules That Use DLLs
Build Dynamic Link Libraries for Resources
Build Subsystems
Change a Build Setup
Build

Build Options