Compiling and Linking a Function Module

From InterBase
Jump to: navigation, search

Go Up to Working with UDFs and Blob Filters


After a UDF module is complete, you can compile it in a normal fashion into object or library format. You then declare the UDFs in the resulting object or library module to the database using the DECLARE EXTERNAL FUNCTION statement. Once declared to the database, the library containing all the UDFs is automatically loaded at run time from a shared library or dynamic link library.

  • Include ibase.h in the source code if you use typedefs defined in the InterBase ibase.h header file. All “include” (*.h) libraries are in the <<InterBase_home>>/SDK/include directory.
  • Link to gds32.dll if you use calls to InterBase library functions.
  • Linking and compiling:

Microsoft Visual C/C++ Link with <<InterBase_home>>/SDK /lib_ms/ib_util_ms.lib and include <<InterBase_home>>/SDK/include/ib_util.h

Use the following options when compiling applications with Microsoft C++:

Microsoft C compiler options
Option Action

c

Compile without linking (DLLs only)

Zi

Generate complete debugging information

DWIN32

Defines “WIN32”

D_MT

Use a multi-thread, statically-linked library

C++ Link with <<InterBase_home>>/SDK/lib/ib_util.lib and include <<InterBase_home>>/SDK/include/ib_util.h

Delphi Use <<InterBase_home>>/SDK/include/ib_util.pas.

Examples: The following commands use the Microsoft compiler to build a DLL that uses InterBase:

cl -c -Zi -DWIN32 -D_MT -LD udf.c
lib -out:udf.dll -def:funclib.def -machine:i586 -subsystem:console
link -DLL -out:funclib.dll -DEBUG:full,mapped -DEBUGTYPE:CV
-machine:i586 -entry:_DllMainCRTStartup@12 -subsystem:console
-verbose udf.obj udf.exp gds32_ms.lib ib_util_ms.lib crtdll.lib

This command builds an InterBase executable using the Microsoft compiler:

cl -Zi -DWIN32 -D_MT -MD udftest.c udf.lib gds32_ms.lib
ib_util_ms.lib crtdll.lib

See the makefiles (makefile.bc and makefile.msc on Windows platforms, makefile on UNIX) in the InterBase examples subdirectory for details on how to compile a UDF library.

Examples: For examples of how to write thread-safe UDFs, see <<InterBase_home>>/examples/UDF/udflib.c.


Creating a UDF Library

UDF libraries are standard shared libraries that are dynamically loaded by the database at runtime. You can create UDF libraries on any platform—except NetWare—that is supported by InterBase. To use the same set of UDFs with databases running on different platforms, create separate libraries on each platform where the databases reside. UDFs run on the server where the database resides.

Note: A library, in this context, is a shared object that typically has a dll extension on Windows platforms, and a so extension on Solaris and Linux.

The InterBase examples directory contains sample makefiles (makefile.bc and makefile.msc on Windows platforms, makefile on UNIX) that build a UDF function library from udflib.c.


Modifying a UDF Library

To add a UDF to an existing UDF library on a platform:

  • Compile the UDF according to the instructions for the platform.
  • Include all object files previously included in the library and the newly-created object file in the command line when creating the function library.
Note: On some platforms, object files can be added directly to existing libraries. For more information, consult the platform-specific compiler and linker documentation.

To delete a UDF from a library, follow the linker’s instructions for removing an object from a library. Deleting a UDF from a library does not eliminate references to it in the database.


Advance To: