user-defined routines
This topic provides information about how to compile and link a user-defined routine (UDR).
func1() that uses the 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.
func1() UDR:cl /MD /DNT_MI_SAPI /DMI_SERVBUILD \
-Id:\msdev\include -Id:\informix\incl\public -Id:\informix\incl
-c func1.cError 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 library, as you do for client applications.
The location of the header file, ifxgls.h, is the $INFORMIXDIR/incl/public directory. This directory contains many of the other files that a client application uses. Make sure that you include this directory with the -I option of the compiler.
Additionally, you need to indicate that the module
is a UDR
(which runs on the server computer), not a client
application (which runs on a client computer). Include the MI_SERVBUILD compiler
flag when you compile a UDR.
udrs.so that
contains the C code for a 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