IBM Books

Administering Satellites Guide and Reference


Building Applications for Satellites

The following sections provide detailed information about building applications for satellites that run Windows 32-bit operating systems.

Microsoft Visual C++

The Visual C++ compiler is used for both C and C++ sample programs supplied in the %DB2PATH%\samples\c and %DB2PATH%\samples\cpp directories. The batch files in both these directories contain commands to accept either a C or C++ source file, depending on the file extension. By default, the C++ commands are commented out in the batch files in %DB2PATH%\samples\c, and the C commands are commented out in the batch files in %DB2PATH%\samples\cpp.

DB2 API Applications

The batch file bldmsapi.bat, in %DB2PATH%\samples\c, and %DB2PATH%\samples\cpp, contains the commands to build a DB2 API program.

The parameter, %1, specifies the name of your source file.

@echo off
rem bldmsapi.bat file
rem Builds a DB2 API program in C or C++
rem using the Microsoft Visual C++ compiler.
rem Usage: bldmsapi prog_name
if "%1" == "" goto error
rem  Compile the C program. 
cl -Z7 -Od -c -W2 -D_X86_=1 -DWIN32 %1.c util.c
rem For C++, comment out the above line, and uncomment the following:
rem cl -Z7 -Od -c -W2 -D_X86_=1 -DWIN32 %1.cxx util.cxx
rem Link the program.
link -debug:full -debugtype:cv -out:%1.exe %1.obj util.obj db2api.lib
goto exit
:error
echo Usage: bldmsapi prog_name
:exit
@echo on

Compile and Link Options for bldmsapi

The batch file contains the following compile options:

cl
The Microsoft Visual C++ compiler.

-Z7
C7 style CodeView information generated.

-Od
Disable optimizations. It is easier to use a debugger with optimization off.

-c
Perform compile only; no link. This book assumes that compile and link are separate steps.

-W2
Set warning level.

-D_X86_=1
Compiler option necessary for Windows 32-bit operating systems to run on Intel-based computers.

-DWIN32
Compiler option necessary for Windows 32-bit operating systems.

The batch file contains the following link options:

link
Use the 32-bit linker to link edit.

-debug:full
Include debugging information.

-debugtype:cv
Indicate the debugger type.

-out:%1.exe
Specify the executable.

%1.obj
Include the object file

db2api.lib
Link with the DB2 library.

Refer to your compiler documentation for additional compiler options.

To build the sample program, client, from either the source file client.c, in %DB2PATH%\samples\c, or from the source file client.cxx, in %DB2PATH%\samples\cpp, enter:

  bldmsapi client

The result is an executable file, client.exe. You can run the executable file by entering the executable name (without the extension) on the command line:

  client

IBM VisualAge C++ Version 3.5

The VisualAge C++ compiler is used for both C and C++ sample programs supplied in the %DB2PATH%\samples\c and %DB2PATH%\samples\cpp directories. The batch files in both these directories contain commands to accept either a C or C++ source file, depending on the file extension. By default, the C++ commands are commented out in the batch files in %DB2PATH%\samples\c, and the C commands are commented out in the batch files in %DB2PATH%\samples\cpp. This section demonstrates building programs using the C batch files.

DB2 API Applications

The batch file bldvaapi.bat, in %DB2PATH%\samples\c, and in %DB2PATH%\samples\cpp, contains the commands to build a DB2 API program.

Ensure that the LIB environment variable points to %DB2PATH%\lib as follows:

  set LIB=%DB2PATH%\lib;%LIB%

The parameter, %1, specifies the name of your source file.

@echo off
rem bldvaapi.bat file
rem Builds a DB2 API program using the IBM VisualAge C++ compiler.
rem USAGE: bldvaapi <prog_name>
rem  Compile the program. 
icc -c -Ti -W1 %1.c util.c
rem For C++, comment out the above line and uncomment the following:
rem icc -c -Ti -W1 %1.c util.cxx
rem  Link the program.
ilink /MAP /DEBUG /ST:32000 /PM:VIO %1.obj util.obj db2api.lib
goto exit
:error
echo Usage: bldvaapi <prog_name>
:exit
@echo on

Compile and Link Options for bldvaapi

The batch file contains the following compile options:

icc
The IBM VisualAge C++ compiler.

-c
Perform compile only; no link. This book assumes that compile and link are separate steps.

-Ti
Generate debugger information.

-W1
Output warning, error, and severe and unrecoverable error messages.

The batch file contains the following link options:

ilink
Use the resource linker to link edit.

/MAP
Generate a map file.

/DEBUG
Include debugging information.

/ST:32000
Specify a stack size of at least 32 000.

/PM:VIO
Enable the program to run in a window or in a full screen.

%1.obj
Include the object file.

util.obj
Include the error-checking utility object file.

db2api.lib
Link with the DB2 library.

Refer to your compiler documentation for additional compiler options.

To build the sample program client from the C source file client.c, or the C++ file client.cxx, enter:

  bldvaapi client

The result is an executable file client.exe. You can run the executable file against the SATCTLDB database by entering the executable name (without the extension):

  client

IBM VisualAge C++ Version 4.0

The VisualAge C++ compiler differs from other compilers on Windows 32-bit operating systems. To compile a program with VisualAge C++ Version 4.0, you must first make a configuration file. For more information, refer to the documentation that is provided with the compiler.

DB2 provides configuration files for the different types of DB2 programs you can build with this VisualAge C++ compiler. To use a DB2 configuration file, first set an environment variable to the program name that you want to compile. Then compile the program with a command supplied by VisualAge C++ Version 4.0. The api.icc file is the DB2 API configuration file. See DB2 API Applications for information on how to use this file to compile your programs. For information about the other DB2 configuration files that are available, refer to the Application Building Guide.

DB2 API Applications

The configuration file, api.icc, in %DB2PATH%\samples\c, allows you to build DB2 API programs in C. There is also a C++ DB2 API configuration file in %DB2PATH%\samples\cpp. These files can be used on AIX, OS/2 and Windows 32-bit operating systems.

// api.icc configuration file for DB2 API programs
// for VisualAge C++ Version 4.0
// To use on AIX, enter: 'export API=prog_name'
// To use on OS/2 and Windows, enter: 'set API=prog_name'
// Then compile the program by entering: 'vacbld api.icc'
 
if defined( $API )
{
  prog_name = $API
}
else
{
  error "Environment Variable API is not defined."
}
 
infile = prog_name".c"
util   = "util.c"
 
if defined( $__TOS_AIX__ )
{
  // Set db2path to where DB2 will be accessed. 
  // The default is the standard instance path.
  db2path     = $HOME"/sqllib"
  outfile     = prog_name
  group lib   = "libdb2.a"
  option opts = link( libsearchpath, db2path"/lib" ),
                incl( searchPath, db2path"/include" )
}
else // if defined( $__TOS_OS2__ ) | defined( $__TOS_WIN__ )
{
  db2path     = $DB2PATH
  outfile     = prog_name".exe"
  group lib   = "db2api.lib"
  option opts = link( libsearchpath, db2path"\\lib" ),
                incl( searchPath, db2path"\\include" )
}
 
option opts
{
  target type(exe) outfile
  {
    source infile
    source util
    source lib
  }
}

VisualAge C++ Version 4.0 defines one of the following environment variables, depending on the operating system on which it is installed: __TOS_AIX__, __TOS_OS2__, __TOS_WIN__.

To use the configuration file to build the DB2 API sample program called client from the source file client.c, do the following:

  1. Set the API environment variable to the program name by entering:
      set API=client
    
  2. If you have an api.ics file in your working directory, produced by building a different program with the api.icc file, delete the api.ics file with this command:
      del api.ics
    

    An existing api.ics file produced for the same program you are going to build again does not have to be deleted.

  3. Compile the sample program by entering:
      vacbld api.icc
    
    Note:The vacbld command is provided by VisualAge C++ Version 4.0.

The result is an executable file, client. You can run the program by entering the executable name:

  client


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ Top of Page ]