Building C/C++ applications on Windows
Db2®
provides build scripts for compiling and linking Db2 API and embedded SQL
C/C++ programs. These are located in the sqllib\samples\c
and
sqllib\samples\cpp
directories, along with sample programs that can be built with
these files.
About this task
The batch file, bldapp.bat
, contains the commands to build Db2 API and embedded SQL
programs. It takes up to four parameters, represented inside the batch file by the variables
%1
, %2
, %3
, and %4
.
The first parameter, %1
, specifies the name of your
source file. This is the only required parameter for programs that
do not contain embedded SQL. Building embedded SQL programs requires
a connection to the database so three additional parameters are also
provided: the second parameter, %2
, specifies the
name of the database to which you want to connect; the third parameter, %3
, specifies the user ID for the database, and %4
specifies the password.
For an embedded SQL program, bldapp
passes the parameters to the precompile and bind
file, embprep.bat
. If no database name is supplied,
the default sample
database is used. The user ID
and password parameters are only needed if the instance where the
program is built is different from the instance where the database
is located.
Procedure
Example
The following examples show you how to build and run Db2 API and embedded SQL applications.
cli_info
, from either the source file cli_info.c
,
in sqllib\samples\c
, or from the source file cli_info.cxx
, in
sqllib\samples\cpp
, enter: bldapp cli_info
The result is
an executable file, cli_info.exe
. You can run the executable file by entering the
executable name (without the extension) on the command line: cli_info