Date: Wed, 29 Dec 1999 18:35:56 -0600 From: Dan Nelson <dnelson@emsphone.com> To: Charlie Root <root@virtual-voodoo.com> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: gcc command line ordering question Message-ID: <19991229183556.A19230@dan.emsphone.com> In-Reply-To: <199912292207.RAA67250@virtual-voodoo.com>; from "Charlie Root" on Wed Dec 29 17:07:53 GMT 1999 References: <199912292207.RAA67250@virtual-voodoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Dec 29), Charlie Root said: > 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? -l specifies libraries. Libraries are special in that symbols are only used when *needed*. Your "-lldap -llber test.c" basically was a no-op for the libraries, since there were no unresolved symbols until "test.o" got linked in and asked for "ldap_init". But by that time it was too late. Moving the libs to the end of the commandline lets them resolve the "ldap_init" symbol. This is why you always see libraries at the *end* of commandlines :) -- Dan Nelson dnelson@emsphone.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?19991229183556.A19230>