DataBlade® user-defined routines

This topic provides information about how to compile and link a DataBlade® user-defined routine (UDR).

The GLS libraries are already linked to the database server. All HCL® Informix® GLS functions are exported through the SAPI.LIB library. Therefore, you do not need to specify the Informix® GLS library explicitly when you compile and link a DataBlade® UDR on Windows. For example, the following commands compile and link a DataBlade® UDR called func1() that uses the Informix® GLS library:
cl /DNT_MI_SAPI /DMI_SERVBUILD
-Id:\msdev\include -Id:\informix\incl\public -Id:\informix\incl
-c func1.c
link /DLL /OUT:func1.dll /DEF:func1.def func1.obj d:\informix\lib\SAPI.LIB

In the preceding example, d: specifies the drive on which Informix® software is installed; informix is the directory that INFORMIXDIR specifies. The resulting dynamic link libraries (DLLs) must have the READONLY attribute set with the attrib +r command.

The Microsoft compiler, cl, defaults to the /MT option, which specifies the multithreaded library for DLL builds. This multithreaded library is statically linked to the DLL. You can specify the /MD option to put MSVCRT40.DLL in a command path. All the UDRs that are built with /MD use one copy of the LIBC DLL. This option prevents virtual-memory buildup in the database server when many UDRs are loaded.

The following example shows the use of the /MD option to compile the func1() DataBlade® UDR:
cl /MD /DNT_MI_SAPI /DMI_SERVBUILD \
-Id:\msdev\include -Id:\informix\incl\public -Id:\informix\incl
-c func1.c
If MSVCRT40.DLL is not visible to the database server, the database server puts the following error in the online.log file when it attempts to execute the UDR:
Error loading UDR

On UNIX platforms, the GLS libraries are not linked to the database server. Therefore, you must explicitly specify the location and name of the Informix® GLS library, as you do for DataBlade® client applications.

The location of the Informix® GLS header file, ifxgls.h, is the $INFORMIXDIR/incl/public directory. This directory contains many of the other files that a DataBlade® client application uses. Make sure that you include this directory with the -I option of the compiler.

Tip: When you use the DataBlade® Developers Kit to compile user-defined routines, you do not have to specify the location of the header files explicitly.

Additionally, you need to indicate that the DataBlade® module is a DataBlade® UDR (which runs on the server computer), not a DataBlade® client application (which runs on a client computer). Include the MI_SERVBUILD compiler flag when you compile a DataBlade® UDR.

The following example builds a shared object called udrs.so that contains the C code for a DataBlade® UDR called func1():
% cc -KPIC -DMI_SERVBUILD -I$INFORMIXDIR/incl/public -I$INFORMIXDIR/incl
-L$INFORMIXDIR/esql/lib -c func1.c
% ld -G func1.o -o udrs.so