From owner-freebsd-questions Fri Nov 17 2: 7:36 2000 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-65-26-235-186.mmcable.com [65.26.235.186]) by hub.freebsd.org (Postfix) with SMTP id B5D9237B479 for ; Fri, 17 Nov 2000 02:07:32 -0800 (PST) Received: (qmail 86737 invoked by uid 100); 17 Nov 2000 10:07:26 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14869.862.286676.479453@guru.mired.org> Date: Fri, 17 Nov 2000 04:07:26 -0600 (CST) To: Henrik.Nilsson@west.se Cc: questions@freebsd.org Subject: Re: Re: Creating libraries with "ar" fails... In-Reply-To: <200011170913.eAH9DEs26928@mail.west.se> References: <200011170913.eAH9DEs26928@mail.west.se> X-Mailer: VM 6.75 under 21.1 (patch 10) "Capitol Reef" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Henrik Nilsson types: > > Thank you very much for your help, it worked like a charm! > > I had no idea the order of the files was important, I just assumed that ar > failed to create > a library file that was correct. My way of thinking was that I line up all .o > and library files > in the beginning so the linker has knowledge about them before linking > although I knew > that linking was the last stage of the process (as the man page says). > > Do you know why the order of files is important, seems to me it shouldn't > have to be... First, please keep -questions mail on -questions. This helps in a number of ways - your acknowledging that the solution worked will help others when they search the archives, other readers of -questions might be interested in the answer to your new question, and they might know the answer if I don't. In this case, I do. The files are linked in order, and libraries are searched for names that haven't been resolved when they are linked. Anything else in the library isn't linked, which lets you have libraries with lots of functions in them, yet link them to get one function without having your executable grow to enormous size. So what happened in your case was that there were no unresolved references when the library was searched, so nothing from it was included in the executable. You then linked in the .o file that that was trying to find things in the .a file that you had already discarded, generating the unresolved reference reports. Changing the order let the .a file resolve all the references from the .o file. thanks, > Henrik Nilsson > > On Thu, 16 Nov 2000, Mike Meyer wrote: > > Date: Thu, 16 Nov 2000 11:10:06 -0600 (CST) > > To: Henrik Nilsson > > From: Mike Meyer > > Subject: Re: Creating libraries with "ar" fails... > > > > Henrik Nilsson types: > > > I'm trying to create an archive file (libxmlnode.a) with one object file > > in it > > > (XmlNode.o), but when I link the archive file with my testprogram I get a > > lot > > > of undefined references. > > > > > > Below you can see the error message. > > > > > > The command I use to create the lib file is: > > > ar rs libxmlnode.a XmlNode.o > > > (with the s parameter you get the same result as running ranlib on the > > > archive later) > > > > > > Is there anything else I need to do in order to get it to work? > > > Or have I just forgot something? > > > > > > regards, > > > Henrik Nilsson > > > > > > ps. please reply to my emailaddress as well, as I'm not a member of this > > > mailinglist. Thanks! ds. > > > > > > - --error message--- > > > g++ -ggdb -Wall -pedantic -Wtraditional -Wshadow -Wpointer-arith > > -Wcast-qual > > > - -Wcast-align -Wconversion -Wstrict-prototypes -Wmissing-declarations > > > - -Wredundant-decls -Woverloaded-virtual -Winline -ansi -pipe > > > '-Dperror(x)={char buff[256]; sprintf(buff, "%s[%d]::%s() reported \"%s\" > > > with reason", __FILE__, __LINE__, __FUNCTION__, x); perror(buff);}' > > > libxmlnode.a main.cpp -o main > > > > Shouldn't the last few be: main.cpp libxmlnode.a -o main > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message