LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   undefined reference? (http://www.linuxquestions.org/questions/programming-9/undefined-reference-499458/)

Sharky01252 11-07-2006 12:27 PM

undefined reference?
 
Hi people,

I am very new to coding in c++ and dont understand what this error means, google has been little help. Here is my code can you please tell me why when i compile i get the following error

Error:
Code:

[alan@localhost work]$ gcc ldap.c -o ldap
/tmp/ccijpbPB.o(.text+0x1e): In function `main':
: undefined reference to `ldap_init'
/tmp/ccijpbPB.o(.text+0x52): In function `main':
: undefined reference to `ldap_simple_bind_s'
/tmp/ccijpbPB.o(.text+0x6c): In function `main':
: undefined reference to `ldaperr2string'
collect2: ld returned 1 exit status


Code:
Code:

#include <stdio.h>
#include <ldap.h>

#define HOSTNAME "localhost"
#define PORT_NUMBER 389
#define FIND_DN "dc=my-domain,dc=com"


int main( int argc, char **argv )
{
          LDAP *ld;
        LDAPMessage *result, *e;
        BerElement *ber;
        char *a;
        char **vals;
        int i, rc;

/* Get a handle to an LDAP Connection */

if( (ld = ldap_init(HOSTNAME,PORT_NUMBER)) == NULL)
        {
        perror( "ldap_init");
        return (1);
        }


/* Bind anonymously to the LDAP Server */

rc = ldap_simple_bind_s (ld,NULL,NULL);

if (rc != LDAP_SUCCESS)
{
fprintf(stderr,"ldap_simple_bind_s: %s\n", ldaperr2string(rc));
return( 1);
}
else
{
printf("Connection Successful");
}

return ( 0 );
}


paulsm4 11-07-2006 12:31 PM

Hi -

Try adding "gcc ldap.c -o ldap -lldap" (include the LDAP library in your build command).

Sharky01252 11-07-2006 12:33 PM

Hmm, that got rid of a couple of errors thank you :)

Still got this now tho

Code:

/tmp/ccMrSEkt.o(.text+0x6c): In function `main':
: undefined reference to `ldaperr2string'
collect2: ld returned 1 exit status

Going to check if thats a typo..

Sharky01252 11-07-2006 12:36 PM

That fixed it completley :)

Thanks very much for your help and quick reply


All times are GMT -5. The time now is 06:07 AM.