Linux CLI routine compile and link options

The compile and link options in this topic are recommended by Db2® for building CLI routines with the GNU/Linux gcc compiler. They are demonstrated in the sqllib/samples/cli/bldrtn build script.

Compile options:

gcc
The C compiler.
$EXTRA_C_FLAGS
Consists of one of the listed flags:
  • -m31 on Linux® for zSeries only, to build a 32-bit library;
  • -m32 on Linux for x86, x64 and POWER®, to build a 32-bit library;
  • -m64 on Linux for zSeries, POWER, x64, to build a 64-bit library; or
  • No value on Linux for IA64, to build a 64-bit library.
-fpic
Allows position independent code.
-I$DB2PATH/include
Specify the location of the Db2 include files. For example: $HOME/sqllib/include.
-c
Perform compile only; no link. Compile and link are separate steps.
-D_REENTRANT
Defines _REENTRANT, needed as the routines may run in the same process as other routines (THREADSAFE) or in the engine itself (NOT FENCED).

Link options:

gcc
Use the compiler as a front end for the linker.
$EXTRA_C_FLAGS
Consists of one of the listed flags:
  • -m31 on Linux for zSeries only, to build a 32-bit library;
  • -m32 on Linux for x86, x64 and POWER, to build a 32-bit library;
  • -m64 on Linux for zSeries, POWER, x64, to build a 64-bit library; or
  • No value on Linux for IA64, to build a 64-bit library.
-o $1
Specify the executable.
$1.o
Include the program object file.
utilcli.o
Include the utility object file for error-checking.
-shared
Generate a shared library.
$EXTRA_LFLAG
Specify the location of the Db2 shared libraries at run time. For 32-bit it contains the value "-Wl,-rpath,$DB2PATH/lib32". For 64-bit it contains the value "-Wl,-rpath,$DB2PATH/lib64".
-L$DB2PATH/$LIB
Specify the location of the Db2 static and shared libraries at link-time. For example, for 32-bit: $HOME/sqllib/lib32, and for 64-bit: $HOME/sqllib/lib64.
-ldb2
Link with the Db2 library.
-lpthread
Link with the POSIX thread library.

Refer to your compiler documentation for additional compiler options.