TITLE
    OPENSTEP 4.2 and Third Party Libraries
Article ID:
Created:
Modified:
70008
12/3/98
11/10/99

TOPIC

    This article describes how to link an OPENSTEP Enterprise 4.2 application against a third-party C library; in this case, the Lightweight Directory Access Protocol (LDAP) library from Netscape.


DISCUSSION

    On Windows NT, shared libraries are stored as dynamically loaded libraries (.DLL) files. To link against a third-party DLL, you also need the associated .LIB file. The .LIB file contains the actual entry point relocations into the DLL. Compiling and linking requires only the header (.h) and .LIB files. At run time, install the .DLL in a directory that appears in your system's PATH environment variable.

    The necessary third party files to link against the LDAP library can be downloaded from Netscape at http://devedge.netscape.com/one/directory/ . For this example we downloaded dk11e32.exe, which is a self-extracting file. The LDAP files were installed in the following locations:

      • nsldap32v11.lib in c:/OpenStep/Lib
      • ldap.h in c:/OpenStep/include (as well as the other LDAP headers)
      • nsldap32v11.dll in c:/Next/NextLibrary/Executables
    To use LDAP, you will also need to set the following environment variables:
      • PATH should include c:/NextLibrayr/Executables
      • INCLUDE should include c:/OpenStep/include
    In ProjectBuilder, add nsldap32v11.lib to the "Libraries" suitcase and import the ldap header in one of your project's existing header files. You will now be able to access the functions of the LDAP library.

    Below is source code from a simple test app. This application will display its version number (110) in a text field when a button is pressed. Note that for this simple test case, no attempt was made to configure an LDAP Directory server.


    //========= AppControl.h =========================================

    #import <AppKit/Appkit.h>
    #define LDAP_API(rt) rt          // <== this did the trick in the test app!
    #import <ldap.h>


    @interface AppControl : NSObject
    {
    id pTextField01;                                  //<==== pointer to text field
    }


    - (void)clickedCallLDAP:(id)sender;  //<=== action method - called when
    //
    button is clicked


    @end

    //==============================================================

    Notice that b efore importing the Netscape  ldap.h  file  in AppControl.h above,
    the following define occurs:


    #define LDAP_API(rt) rt

    Without this line LDAP_API will get set this way (in ldap.h):

    #define LDAP_API(rt) __declspec( dllexport ) rt

    This definition will generate wrong linker symbols that will not be
    found in the library. The result is linker errors (error LNK2001: unresolved
    external symbol ....). Below is the implementation file.

    //============ AppControl.m ======================================

    #import "AppControl.h"

    @implementation AppControl

    - (void)clickedCallLDAP:(id)sender
    {
    LDAPVersion ver;
    double SDKVersion;


    SDKVersion = ldap_version( &ver );              //<=== get version number

    printf("LDAP version = %7.3f\n", SDKVersion);
    [pTextField01 setIntValue:SDKVersion];        //<=== display in text field
    }


    @end

    //==============================================================


Document Information
Product Area: Apple Software
Category: OPENSTEP
Sub Category: Development
Keywords:

Copyright © 2000 Apple Computer, Inc. All rights reserved.