2.3. Compiling a Directory Server Plug-in

Keep in mind the following tips when compiling the server plug-in:
  • Compile and link the code as a shared object or library.
    On Red Hat Enterprise Linux, use -shared with gcc:
    gcc -shared
    On Solaris, use this as the link command:
    ld -G objects -o shared_object
    Some compilers require special flags to be used when compiling code a shared object. On Linux, this is done with the -fPIC flag with gcc to generate position-independent code. On Solaris, this uses the -KPIC flag. Consult the documentation for the platform compiler and linker for details.
  • Ensure that the directory with the slapi-plugin.h file is in the include path directive. For example:
    gcc -I /usr/lib64/dirsrv/plugins
    It is also possible to define the location of the header file in the plug-in file. Some platforms install the header file with the 389-ds-base-devel package, which installs the header file in the /usr/include/dirsrv. In that case, it is not necessary to specify the full path in the plug-in file.
    #include dirsrv/slapi-plugin.h
  • All plug-in functions can be compiled in a single library. Although different types of plug-in functions can be included in the same library, separate initialization functions need to be written for each type of plug-in function. It is also possible to use an object type plug-in.
    See Chapter 3, Configuring Plug-ins for details on how to specify each initialization function in a directive for a specific type of plug-in.
Example 2.2, “Makefile for Example Plug-ins” assumes that 389-ds-base-devel package has been installed or that the header file, slapi-plugin.h, is in /usr/include/dirsrv.

Example 2.2. Makefile for Example Plug-ins

# Makefile for Directory Server plug-in examples
#
CC = gcc
LD = gcc
CFLAGS = -fPIC -I /usr/include/nspr4 -Wall
LDFLAGS = -shared -z defs -L/usr/lib64/dirsrv -lslapd
OBJS = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o
all: libtest-plugin.so
libtest-plugin.so: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $(OBJS)
.c.o:
$(CC) $(CFLAGS) -c $<
clean:
-rm -f $(OBJS) libtest-plugin.so