Home | Previous Page | Next Page   Creating User-Defined Routines > Developing a User-Defined Routine > Compiling a C UDR >

Creating a Shared-Object File

You create a shared-object file to hold the compiled UDRs. This file resides in a directory on the server computer. Each UDR must have a unique name within the shared-object file.

UNIX/Linux Only

On UNIX or Linux a shared-object file is often called a shared library. On Solaris systems, shared-object files have the .so file extension.

End of UNIX/Linux Only
Windows Only

On Windows a shared-object file is called a dynamic link library (DLL). DLLs usually have the .dll file extension.

End of Windows Only

When the database server executes an SQL statement that contains a UDR, it loads in memory the shared-object file in which the UDR executable code resides. It determines which shared-object file to load from the externalname column of the row in the sysprocedures system catalog table that describes the UDR. The CREATE FUNCTION or CREATE PROCEDURE statement creates a row for a UDR in sysprocedures when it registers the UDR.

To create a shared-object file for a C UDR
  1. Create a shared-object file and put the UDR object (.o file) file into this shared-object file.

    You can put C functions for related UDRs into the same shared-object file. However, the name of each C function must be unique within the shared-object file.

  2. Put the shared-object file in a directory on which the user informix has read permission and the shared-object owner has write permission.

    The shared-object file must not have permissions that allow any user other than user informix to have write permission.

  3. Specify the path of the shared-object file in the EXTERNAL NAME clause of the CREATE FUNCTION (or CREATE PROCEDURE) statement when you register the C UDR.

    The shared-object file does not have to exist before you register its path with CREATE FUNCTION or CREATE PROCEDURE. However, at UDR runtime, the paths of the shared-object file and the registered UDR must match for the database server to locate the UDR.

Important:
If a shared-object file has write permission set to all, the database server issues error -9793 and writes a message in the log file when someone tries to execute any UDR in the shared object.
Note:
For more information, see Executing a UDR. For information on how to create a shared-object file, see the IBM Informix: User-Defined Routines and Data Types Developer's Guide.
To create a shared-object file on UNIX or Linux
  1. Load the abs.o object file into the abs.so shared library, as the following example shows:
    /compilers/bin/cc -K abs.o -o abs.so
    
    ld -G abs.o -o abs.so
  2. Put the shared library in a directory on which user informix has read permission and set the permissions to 755 or 775 so that only the owner can write to the shared libraries.
    # ls -ld /usr/code
    drwxr-xr-x 12 informix devel 2560 Feb 25 05:27 /usr/code 
    # chmod 775 /usr/code/abs.so
    drwxrwxr-x 12 informix devel 2560 Feb 25 05:27
       /usr/code 
To create a shared-object file on Windows
  1. Load the abs.o object file into the abs.so DLL:, as the following example shows:
    link /DLL /OUT:abs.dll /DEF:abs.def abs.obj 
       d:\informix\lib\SAPI.LIB

    The preceding command uses the IBM Informix software installed on the d: drive in a directory named informix.

  2. Put the DLL in a directory on which user informix has read permission and set the READONLY attribute with the attrib +r command:
    attrib 
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]