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.
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?
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
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.