Show Table of Contents
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
-sharedwithgcc: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-fPICflag withgccto generate position-independent code. On Solaris, this uses the-KPICflag. Consult the documentation for the platform compiler and linker for details. - Ensure that the directory with the
slapi-plugin.hfile 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 the389-ds-base-develpackage, 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
objecttype 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

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.