Home » Language IDEs » CDT » C LDAP compile error-Noob (Building C LDAP)
C LDAP compile error-Noob [message #495470] Wed, 04 November 2009 19:54 Go to next message
Swami   is currently offline Swami
Messages: 4
Registered: November 2009
Junior Member
I'm using Eclipse CDT on CentOS 5.3. I'm new to Eclipse CDT, C & LDAP.
I want to build a C app talking to my local LDAP server.

#include <ldap.h>
int main(void) {
LDAP *ld;
ldap_initialize(&ld, "ldap://localhost/");
}

Building this code gives me an error:

make all
Building file: ../src/ldaptest1.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ldaptest1.d" -MT"src/ldaptest1.d" -o"src/ldaptest1.o" "../src/ldaptest1.c"
Finished building: ../src/ldaptest1.c

Building target: ldaptest1
Invoking: GCC C Linker
gcc -o"ldaptest1" ./src/ldaptest1.o
./src/ldaptest1.o: In function `main':
/home/swami/test/ldaptest1/Debug/../src/ldaptest1.c:8: undefined reference to `ldap_initialize'
collect2: ld returned 1 exit status
make: *** [ldaptest1] Error 1

Any clue what I'm doing wrong? Any help appreciated.
Re: C LDAP compile error-Noob [message #495581 is a reply to message #495470 ] Thu, 05 November 2009 07:12 Go to previous messageGo to next message
Axel Mueller  is currently offline Axel Mueller
Messages: 277
Registered: July 2009
Senior Member
Quote:
/home/swami/test/ldaptest1/Debug/../src/ldaptest1.c:8: undefined reference to `ldap_initialize'
collect2: ld returned 1 exit status
make: *** [ldaptest1] Error 1

Any clue what I'm doing wrong? Any help appreciated.

You need to tell the linker which library to link to (ldap).
Re: C LDAP compile error-Noob [message #495677 is a reply to message #495581 ] Thu, 05 November 2009 13:00 Go to previous messageGo to next message
Swami   is currently offline Swami
Messages: 4
Registered: November 2009
Junior Member
Thanks a lot for responding.
I tried adding a linker called GLLB from what I could find on the net but I continue to get the same error. Is anyone familiar with OpenLDAP & C who can help me here?
Re: C LDAP compile error-Noob [message #495979 is a reply to message #495677 ] Fri, 06 November 2009 15:47 Go to previous messageGo to next message
Swami   is currently offline Swami
Messages: 4
Registered: November 2009
Junior Member
Based on the openldap doc: http://www.openldap.org/software/man.cgi?query=ldap

I tried linking to the openldap library: (libldap, -lldap) using the following command but still stumped.
I tried several options without any success:
gcc -L/usr/lib64/libldap-2.3.so.0.2.31 -o"ldaptest1" ./src/ldaptest1.o
gcc -L/usr/lib64/ -o"ldaptest1" ./src/ldaptest1.o
gcc -L/usr/lib64/libldap.so -o"ldaptest1" ./src/ldaptest1.o
gcc -L/...<custom directory where I'm trying to build openldap>/openldap-2.3.43/libraries/libldap -o"ldaptest1" ./src/ldaptest1.o

Any help appreciated. Thanks.

Re: C LDAP compile error-Noob [message #495981 is a reply to message #495677 ] Fri, 06 November 2009 16:13 Go to previous messageGo to next message
Marc-Andre Laperle  is currently offline Marc-Andre Laperle
Messages: 15
Registered: July 2009
Junior Member
Did you try this one?
gcc -o"ldaptest1" -L/usr/lib64/ -lldap ./src/ldaptest1.o

The equivalent in Eclipse is Linker settings, Libraries, add ldap to the Library list (don't add -l) and add /usr/lib64 to the Library search path list.

I did something similar on Mac using openldap from MacPorts using you code and it worked.
Re: C LDAP compile error-Noob [message #495996 is a reply to message #495981 ] Fri, 06 November 2009 17:47 Go to previous message
Swami   is currently offline Swami
Messages: 4
Registered: November 2009
Junior Member
This worked. Thanks a ton!
Previous Topic:Binaries not created in Snow Leopard (64 bit problem?)
Next Topic:Linking object file to static library project
Goto Forum: