IBM Books

Building Applications for UNIX** Environments


Compiling and Linking by Platform

The script file clibld contains the commands to build the sample DB2 CLI program clisampl.c. You can find both the script file and clisampl.c in sqllib/samples/cli.

Study the script file's compile and link options for the platform you are using. Then go to "Building and Running a CLI Program" for the steps to follow in order to build and run the program.

AIX

IBM XL C is used in the following version of the clibld script file:




#! /bin/ksh
# clibld script file -- AIX
# Build clisampl
 
# Compile the program.
xlc -I/usr/lpp/db2_05_00/include -c clisampl.c
 
# Compile the common utility functions used by most CLI sample programs
xlc -I/usr/lpp/db2_05_00/include -c samputil.c
 
# Link the program.
xlc -o clisampl clisampl.o samputil.o -L/usr/lpp/db2_05_00/lib -ldb2


Compile and Link Options for clibld

The script file contains the following compile options:

xlc
The IBM XL C compiler.

-Ipath
Specify the location of the DB2 include files. For example: -I/usr/lpp/db2_05_00/include

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

The script file contains the following link options:

xlc
Use the compiler to link edit.

-o filename
Specify the name of the executable program.

samputil.o
Include the utility object file for error checking.

-Lpath
Specify the location of the DB2 runtime shared libraries. For example: -L/usr/lpp/db2_05_00/lib. If you do not specify the -L option, the compiler assumes the following path: /usr/lib:/lib.

-ldb2
Link with the database manager library.

Refer to your compiler documentation for additional compiler options.

Note:Multi-threaded applications on AIX Version 4 need to be compiled and linked with the xlc_r compiler instead of the xlc compiler, or with the xlC_r compiler instead of the xlC compiler. See "Multi-threaded Applications" for more information on building C multi-threaded applications.

HP-UX

HP-UX C is used in the following version of the clibld script file:




#! /bin/ksh
# clibld script file -- HP-UX
# Build clisampl
 
# Compile the program.
cc -Aa +DAportable +e -I/opt/IBMdb2/V5.0/include -c clisampl.c
 
# Compile the common utility functions used by most CLI sample programs
cc -Aa +DAportable +e -I/opt/IBMdb2/V5.0/include -c samputil.c
 
# Link the program.
cc +DAportable -o clisampl clisampl.o samputil.o -L/opt/IBMdb2/V5.0/lib -ldb2 -lhppa


Compile and Link Options for clibld

The script file contains the following compile options:

cc
Use the C compiler.

-Aa
Use ANSI standard mode.

+DAportable
Generate code compatible across PA_RISC 1.1 and 2.0 workstations and servers.

+e
Enables HP value-added features while compiling in ANSI C mode.

-Ipath
Specify the location of the DB2 include files. For example: -I/usr/IBMdb2/V5.0/include

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

The script file contains the following link options:

cc
Use the compiler to link edit.

+DAportable
Use code compatible across PA_RISC 1.1 and 2.0 workstations and servers.

-o filename
Specify the name of the executable program.

samputil.o
Include the utility object file for error checking.

-Lpath
Specify the location of the DB2 runtime shared libraries.

-ldb2
Link with the database manager library.

-lhppa
Specify the HP PA-RISC library (required).

Refer to your compiler documentation for additional compiler options.

Note:Multi-threaded applications on HP-UX version 11 need to have _REENTRANT defined for their compilation. The HP-UX documentation recommends compiling with -D_POSIX_C_SOURCE=199506L. This will also ensure _REENTRANT is defined. Applications also need to be linked with -lpthread. Multi-threaded applications are not supported by DB2 on HP-UX version 10. See "Multi-threaded Applications" for more information on building C multi-threaded applications.

SCO UnixWare 7

SCO UnixWare 7 Optimizing C Compilation System is used in the following version of the clibld script file:



#! /bin/ksh
# clibld script file
# Build clisampl
 
# Compile the program.                      
cc -Kthread -I/opt/IBMdb2/V5.0/include -c clisampl.c
 
# Compile the common utility functions used by most CLI sample programs
cc -Kthread -I/opt/IBMdb2/V5.0/include -c samputil.c
 
# Link the program.                                 
cc -o clisampl clisampl.o samputil.o -Kthread -L/opt/IBMdb2/V5.0/lib -ldb2


Compile and Link Options for clibld

The script file contains the following compile options:

cc
The C compiler.

-Kthread
Use the compiler's multi-threaded facilities and arrange for the appropriate preprocessor flags to be turned on.

-Ipath
Specify the location of the DB2 include files. For example: -I/opt/IBMdb2/V5.0/include

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

The script file contains the following link options:

cc
Use the compiler to link edit.

-o $1
Specify the name of the object module.

samputil.o
Include the utility object file for error checking.

-Kthread
Link the threading library in the correct library order.

-Lpath
Specify the location of the DB2 static and shared libraries at link-time. For example: -L/opt/IBMdb2/V5.0/lib. If you do not specify the -L option, /usr/lib:/lib is assumed.

-ldb2
Link with the DB2 library.

Refer to your compiler documentation for additional compiler options.

Note:SCO UnixWare 7 C multi-threaded applications use Unix International threads APIs, which require that the thread.h and synch.h header files be included in the program compilation. See "Multi-threaded Applications" for more information on building C multi-threaded applications.

Silicon Graphics IRIX

DB2 for Silicon Graphics IRIX is client-only. To run DB2 applications, you need to access a DB2 database on a server machine from your client machine. The server machine will be running a different operating system. See Quick Beginnings for UNIX for information on configuring client-to-server communication.

Also, since you will be accessing a database on the server from a remote client that is running on a different operating system, you need to bind the database utilities, including the DB2 CLI, to the database. See "Binding" for more information.

The MIPSpro C compiler is used in the following version of the clibld script file:



#! /bin/ksh
# clibld script file
# Build clisampl
 
# Compile the program.                              
cc -I/opt/IBMdb2/V5.0/include -c clisampl.c
 
# Compile the common utility functions used by most CLI sample programs
cc -I/opt/IBMdb2/V5.0/include -c samputil.c
 
# Link the program.
ld -o clisampl clisampl.o samputil.o -L/opt/IBMdb2/V5.0/lib 
  -rpath /opt/IBMdb2/V5.0/lib -ldb2


Compile and Link Options for clibld

The script file contains the following compile options:

cc
Use the C compiler.

-Ipath
Specify the location of the DB2 include files. For example: -I/opt/IBMdb2/V5.0/include

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

The script file contains the following link options:

ld
Use the linker to link edit.

-o $1
Specify the name of the object module.

samputil.o
Include the utility object file for error checking.

-Lpath
Specify the location of the DB2 static and shared libraries at link-time. For example: -L/opt/IBMdb2/V5.0/lib. If you do not specify the -L option, /usr/lib:/lib is assumed.

-rpath path
Specify the location of the DB2 shared libraries at run-time. For example: -rpath /opt/IBMdb2/V5.0/lib.

-ldb2
Link with the DB2 library.

Refer to your compiler documentation for additional compiler options.

Solaris

SPARCompiler C is used in the following version of the clibld script file:




#! /bin/ksh
# clibld script file -- Solaris
# Build clisampl
 
# Compile the program.
cc -I/opt/IBMdb2/V5.0/include -c clisampl.c
 
# Compile the common utility functions used by most CLI sample programs
cc -I/opt/IBMdb2/V5.0/include -c samputil.c
 
# Link the program.
cc -o clisampl clisampl.o samputil.o -L/opt/IBMdb2/V5.0/lib -R/opt/IBMdb2/V5.0/lib -ldb2


Compile and Link Options for clibld

The script file contains the following compile options:

cc
Use the C compiler.

-Ipath
Specify the location of the DB2 include files. For example: -I/usr/IBMdb2/V5.0/include

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

The script file contains the following link options:

cc
Use the compiler to link edit.

-o filename
Specify the name of the executable program.

samputil.o
Include the utility object file for error checking.

-Lpath
Specify the location of the DB2 static and shared libraries at link-time.

-Rpath
Specify the location of the DB2 shared libraries at run-time.

-ldb2
Link with the DB2 library.

Refer to your compiler documentation for additional compiler options.

Note:Multi-threaded applications using SPARCompiler C on Solaris need to be compiled with -mt. This will pass -D_REENTRANT to the preprocessor, and -lthread to the linker. Posix threads also require -lpthread to be passed to the linker. In addition, using the compiler option -D_POSIX_PTHREAD_SEMANTICS allows posix variants of functions such as getpwnam_r(). See "Multi-threaded Applications" for more information on building C multi-threaded applications.


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

[ DB2 List of Books | Search the DB2 Books ]