Date: Fri, 17 Nov 2000 04:07:26 -0600 (CST) From: Mike Meyer <mwm@mired.org> To: Henrik.Nilsson@west.se Cc: questions@freebsd.org Subject: Re: Re: Creating libraries with "ar" fails... Message-ID: <14869.862.286676.479453@guru.mired.org> In-Reply-To: <200011170913.eAH9DEs26928@mail.west.se> References: <200011170913.eAH9DEs26928@mail.west.se>
next in thread | previous in thread | raw e-mail | index | archive | help
Henrik Nilsson <Henrik.Nilsson@west.se> 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. <mike > thanks, > Henrik Nilsson > > On Thu, 16 Nov 2000, Mike Meyer wrote: > > Date: Thu, 16 Nov 2000 11:10:06 -0600 (CST) > > To: Henrik Nilsson <Henrik.Nilsson@west.se> > > From: Mike Meyer <mwm@mired.org> > > Subject: Re: Creating libraries with "ar" fails... > > > > Henrik Nilsson <Henrik.Nilsson@west.se> 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 > > > > <mike > > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?14869.862.286676.479453>