1

I have a smal testing program to test ldap. I tried to compile it on Ubuntu 19.04. I have the source file called myldaptest.c, I ran: 1.gcc -c myldaptest.c 2.gcc -L/usr/lib/x86_64-linux-gnu -lldap -llber -o myldaptest myldaptest.o

then the it complains: /usr/bin/ld: ldapsearch-sync.o: in function main': ldapsearch-sync.c:(.text.startup+0x236): undefined reference toldap_url_parse' /usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x30b): undefined reference to ldap_initialize' /usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x33a): undefined reference toldap_set_option' /usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x374): undefined reference to ldap_set_option' /usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3a3): undefined reference toldap_set_option' /usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3ea): undefined reference to ldap_set_option' /usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x422): undefined reference toldap_set_option' ... collect2: error: ld returned 1 exit status

who can tell me why?

PeterS
  • 11
  • 1
  • Try moving -L and -l switches at the end "gcc -o myldaptest myldaptest.o -L/usr/lib/x86_64-linux-gnu -lldap -llber" – Icarus3 Dec 09 '19 at 19:38
  • Hi lcarus3, it magically worked, I don't understand why the order matters! Thank you very much, it stopped me for a few hours! – PeterS Dec 09 '19 at 20:05
  • 1
    Unix linkers are single pass linker: https://stackoverflow.com/questions/21854309/why-do-i-have-to-pass-libraries-in-the-end-of-linker-line – Icarus3 Dec 09 '19 at 20:05

0 Answers0