LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-07-2006, 11:27 AM   #1
Sharky01252
Member
 
Registered: Nov 2004
Posts: 31

Rep: Reputation: 15
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 );
}
 
Old 11-07-2006, 11:31 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Try adding "gcc ldap.c -o ldap -lldap" (include the LDAP library in your build command).
 
Old 11-07-2006, 11:33 AM   #3
Sharky01252
Member
 
Registered: Nov 2004
Posts: 31

Original Poster
Rep: Reputation: 15
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..
 
Old 11-07-2006, 11:36 AM   #4
Sharky01252
Member
 
Registered: Nov 2004
Posts: 31

Original Poster
Rep: Reputation: 15
That fixed it completley

Thanks very much for your help and quick reply
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
undefined reference to `_g_list_length' jlkuo56linuxqu General 5 07-12-2006 04:09 AM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM


All times are GMT -5. The time now is 10:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration