From owner-freebsd-hackers Thu Dec 30 0:24:31 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.xmission.com (mail.xmission.com [198.60.22.22]) by hub.freebsd.org (Postfix) with ESMTP id 5DD51151D3 for ; Thu, 30 Dec 1999 00:24:29 -0800 (PST) (envelope-from wes@softweyr.com) Received: from [204.68.178.39] (helo=softweyr.com) by mail.xmission.com with esmtp (Exim 3.03 #3) id 123asl-0003a2-00; Thu, 30 Dec 1999 01:24:28 -0700 Message-ID: <386B174E.93083E6C@softweyr.com> Date: Thu, 30 Dec 1999 01:26:54 -0700 From: Wes Peters Organization: Softweyr LLC X-Mailer: Mozilla 4.7 [en] (X11; U; FreeBSD 3.3-RELEASE i386) X-Accept-Language: en MIME-Version: 1.0 To: Charlie Root Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: gcc command line ordering question References: <199912292207.RAA67250@virtual-voodoo.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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