[Date Prev][Date Next] [Chronological] [Thread] [Top]

Why it always says "undefined reference to `ldap_open' "



HI,

I am an university student and I am learning Linux these days. I
installed the openLDAP server bundled in the RedHat CD-ROM, including
the server, the client and the development libraries. however, I can't
use the API functions in C/C++. 
 
I can find these functions in man, but I can't use them in C. gcc will
report the following while compiling.

i tried the follwing program 'just_bind.c'

   /* example #1
    *  file: just_bind.c
    */
    
    #include <stdio.h>
    #include <ldap.h>
    
    main()
    {
            LDAP            *ld;
            char            *User = NULL;
            char            *Passwd = NULL;
    
    /* open a connection */
    if ((ld = ldap_open("saturn.itso.austin.ibm.com", LDAP_PORT)) ==
NULL) {
                    fprintf(stderr, "ldap_open call failed !");
                    exit(1);
    }
    
    /* authenticate as nobody */
    if (ldap_simple_bind_s(ld, User, Passwd) != LDAP_SUCCESS) {
                    ldap_perror(ld, "ldap_simple_bind_s");
                    exit(1);
    }
    
    /* ..............
    *   do something, for example
    *   ask the server for information
    ...........  */
    
    /* close and free connection resources */
    ldap_unbind(ld);
    exit(0);
    }
    
   
but when i use gcc to compile, i always get the following error message.

/tmp/cc9QVHBS.o(.text+0x2c): undefined reference to `ldap_open'
/tmp/cc9QVHBS.o(.text+0x69): undefined reference to `ldap_simple_bind_s'
/tmp/cc9QVHBS.o(.text+0x80): undefined reference to `ldap_perror'
/tmp/cc9QVHBS.o(.text+0x98): undefined reference to `ldap_unbind'

any suggestion is greatly appreciated. 
 
Thanks and best regards,
 
Max Qian