From owner-freebsd-hackers Wed Dec 29 16:36: 5 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by hub.freebsd.org (Postfix) with ESMTP id ED7C21508D for ; Wed, 29 Dec 1999 16:36:03 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.9.3/8.9.3) id SAA19305; Wed, 29 Dec 1999 18:35:56 -0600 (CST) (envelope-from dan) Date: Wed, 29 Dec 1999 18:35:56 -0600 From: Dan Nelson To: Charlie Root Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: gcc command line ordering question Message-ID: <19991229183556.A19230@dan.emsphone.com> References: <199912292207.RAA67250@virtual-voodoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <199912292207.RAA67250@virtual-voodoo.com>; from "Charlie Root" on Wed Dec 29 17:07:53 GMT 1999 X-OS: FreeBSD 4.0-CURRENT Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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