Sun Java System LDAP SDK for C Programming Guide |
Chapter 2
Sample ClientThe Sun Java System LDAP SDK for C provides a simple example of a Lightweight Directory Access Protocol (LDAP) client. This chapter explains the details. It contains the following sections:
The Source CodeCode Example 2-1 is the source code for a command-line program that retrieves the full name, last name, email address, and telephone number of Barbara Jensen.
Compiling the ClientThe method used to compile the source code depends on the operating system on which you will run the application. The following sections include instructions for compiling on the Solaris Operating System and Microsoft® Windows NT.
Compiling on Solaris
The examples directory (located in DSRK_base/lib/ldapcsdk) contains a UNIX® Makefile. You can modify the Makefile to compile the sample by adjusting the flags specified in the file. The Makefile assumes that the LDAP SDK for C header files are located in the ../include directory. Code Example 2-2 details the Makefile flags.
Code Example 2-2 Solaris Makefile for Sample Client
#
# Makefile for the example in this chapter.
#
EXTRACFLAGS=
EXTRALDFLAGS=-lsocket -lnsl
LDAPLIB=ldap41 -lplc3 -lplds3 -lnspr3
INCDIR=../include
LIBDIR=../lib
LIBS=-L$(LIBDIR) $(LDAPLIB) $(EXTRALDFLAGS)
OPTFLAGS=-g
CFLAGS=$(OPTFLAGS) -I$(INCDIR) $(EXTRACFLAGS)
CC=cc
PROGS=rdentry
all: $(PROGS)
rdentry: rdentry.o
$(CC) -o rdentry rdentry.o $(LIBS)
clean:
/bin/rm -f $(PROGS) *.o a.out core
Compiling on Windows NT
If you are compiling the sample client on Windows NT, set up a makefile for this application. Make sure to:
- Create a new project workspace for a console application and add the source file to the project if you are using Microsoft Visual C++.
- Set your options to include lib as one of the directories containing library files and include as one of the directories containing include files.
- Link to nsldap32v41.lib, the LDAP API import library for Windows.
Running the ClientBefore running the sample client, make sure that your LDAP server is set up with the entry the sample will attempt to find. Unless you change the source code in Code Example 2-1, the entry would be for the full name, last name, email address, and telephone number of Barbara Jensen.
Running on UNIX
If you have compiled and linked the client on a UNIX platform, make sure to set your LD_LIBRARY_PATH environment variable to the location of the libldap41.so, plc3, plds3, and nspr3 library files.
Note
As an alternative, when linking the file, specify the option that identifies the library directories for which the runtime linker should search. For example, on Solaris, use the -R to specify the location of the libldap41.so file.
Running on Windows NT
If you have linked the client with the nsldap32v41.lib import library on Windows NT, make sure to copy the nsldap32v41.dll file to one of the following directories: