Building the DLL

To compile a function that uses the Open Server API, you can use any compiler that can produce the required DLL on your server platform.

For general information about compiling and linking, see the Open Client/Server Supplement.

Search Order for DLLs

Windows searches for DLLs in a ccertain order.

The order is:
  1. The directory from which the application was invoked

  2. The current directory

  3. The system directory (SYSTEM32)

  4. Directories listed in the PATH environment variable

UNIX searches for the library in the directories listed in the LD_LIBRARY_PATH environment variable (on Solaris), SHLIB_PATH (on HP), or LIBPATH in AIX, in the order in which they are listed.

If XP Server does not find the library for an ESP function in the search path, it attempts to load it from $SAP/DLL on Windows or $SAP/lib on other platforms.

Absolute path names for the DLL are not supported.

Sample Makefile (UNIX)

A sample makefile, make.unix, used to create the dynamically linked shared library for the xp_echo program on UNIX platforms.

It generates a file named examples.so on Solaris, and examples.sl on HP. The source is in $SAP/$SAP_ASE/sample/esp, so you can modify it for your own use.

To build the example library using this makefile, enter:

make -f make.unix
#
# This makefile creates a shared library.  It needs the open
# server header
# files usually installed in $SAP/include directory.
# This make file can be used for generating the template ESPs.
# It references the following macros:
#
# PROGRAM is the name of the shared library you may want to create.PROGRAM        = example.so
BINARY        = $(PROGRAM)
EXAMPLEDLL    = $(PROGRAM)

# Include path where ospublic.h etc reside. You may have them in 
# the standard places like /usr/lib etc.

INCLUDEPATH    = $(SAP)/include

# Place where the shared library will be generated.
DLLDIR        = .

RM        = /usr/bin/rm
ECHO        = echo
MODE        = normal

# Directory where the source code is kept.
SRCDIR        = .

# Where the objects will be generated.
OBJECTDIR    = .

OBJS        = xp_echo.o

CFLAGS        = -I$(INCLUDEPATH)
LDFLAGS        =  $(GLDFLAGS) -Bdynamic

DLLLDFLAGS    =  -dy -G
#================================================================

$(EXAMPLEDLL) : $(OBJS) 
    -@$(RM) -f $(DLLDIR)/$(EXAMPLEDLL)
    -@$(ECHO) "Loading $(EXAMPLEDLL)"
    -@$(ECHO) " "
    -@$(ECHO) "    MODE:           $(MODE)"
    -@$(ECHO) "    OBJS:           $(OBJS)"
    -@$(ECHO) "    DEBUGOBJS:      $(DEBUGOBJS)"
    -@$(ECHO) " "    

    cd $(OBJECTDIR); \
    ld -o $(DLLDIR)/$(EXAMPLEDLL) $(DEBUGOBJS) $(DLLLDFLAGS) $(OBJS) 
    -@$(ECHO) "$(EXAMPLEDLL) done"
    exit 0

#================================================================
$(OBJS) : $(SRCDIR)/xp_echo.c 
    cd $(SRCDIR); \
    $(CC) $(CFLAGS) -o $(OBJECTDIR)/$(OBJS) -c xp_echo.c

Sample Definitions File

A sample definitions file that lists every function to be used as an ESP function in the EXPORTS section.

The following file, xp_echo.def, must be in the same directory as xp_echo.mak.
LIBRARY   examples

CODE      PRELOAD MOVEABLE DISCARDABLE
DATA      PRELOAD SINGLE

EXPORTS
        xp_echo  .   1