Date: Thu, 30 Dec 1999 01:26:54 -0700 From: Wes Peters <wes@softweyr.com> To: Charlie Root <root@virtual-voodoo.com> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: gcc command line ordering question Message-ID: <386B174E.93083E6C@softweyr.com> References: <199912292207.RAA67250@virtual-voodoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Charlie Root wrote: > > I have a tiny little snippit of code here (test.c): > > char ldap_init(); > int main(int argc, char **argv) > { > ldap_init(); > return 0; > } > > I expect (want) a runtime error but I do expect it to compile when > linked with the openldap libraries. Here's my quandery: > > vv# gcc -L/usr/local/lib -I/usr/local/include -lldap -llber test.c > /tmp/ccj67244.o: In function `main': > /tmp/ccj67244.o(.text+0x7): undefined reference to `ldap_init' > > Very odd... but if I changed the ordering of the arguments: > > vv# gcc -L/usr/local/lib -I/usr/local/include test.c -lldap -llber > vv# > > It compiles fine. I thought gcc proccessed files in the order in which > they appeard? I further thought that the only difference between > specifying a fullname and using -l was that -l surrounding the name > with lib*.a and searched multiple directories. If thats all true why > would the ordering matter here? The linker, ld, searches libraries for undefined symbols. By specifying -lldap before test.c on the command line, you told ld to scan libldap.a, then compile test.c, which creates a reference to ldap_init that cannot be resolved. Compiling test.c first creates the reference, which is later resolved by searching libldap.a. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC wes@softweyr.com http://softweyr.com/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?386B174E.93083E6C>