From owner-freebsd-questions Wed May 8 18:53:34 2002 Delivered-To: freebsd-questions@freebsd.org Received: from hawk.mail.pas.earthlink.net (hawk.mail.pas.earthlink.net [207.217.120.22]) by hub.freebsd.org (Postfix) with ESMTP id DA4CD37B403; Wed, 8 May 2002 18:53:29 -0700 (PDT) Received: from dialup-209.245.138.5.dial1.sanjose1.level3.net ([209.245.138.5] helo=mindspring.com) by hawk.mail.pas.earthlink.net with esmtp (Exim 3.33 #2) id 175d7V-0004u2-00; Wed, 08 May 2002 18:53:25 -0700 Message-ID: <3CD9D669.9175E309@mindspring.com> Date: Wed, 08 May 2002 18:52:41 -0700 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Mikhail Teterin Cc: questions@FreeBSD.org, current@FreeBSD.org Subject: Re: does the order of .a files matter? References: <200205082044.09459.mi+mx@aldan.algebra.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Mikhail Teterin wrote: > I'm trying to port a huge application to FreeBSD. The app's build > process creates over a hundred of static libraries (.a) and then tries > to link them (and a few object files) into the executable. The process > seems to work fine on the existing platforms (a number of Unixes and > NT), but on FreeBSD I keep getting unresolved symbols. > > The most frustrating thing is, the number of such symbols varies greatly > with the order, in which I list the libraries on the command line. Is > not the linker supposed to make several runs over the given libraries if > needed? No. It doesn't make several runs. It only does that for single object files. You might also want to consider using -L -l, instead of trying to link .a's directly. > It "almost" works, if I try to bypass the libraries completely and just > link all of object files, but for the real application I hit the shell's > limit on the number of arguments -- there are too many object files. > > Any suggestions? Thanks a lot! Order matters. 1) Make sure all your .a files have been ranlib'ed. 2) Order the library arguments on the linker line in dependency order. It was really common in the past to have to include X11 libraries several times on the linker command line in order to get all the symbols resolved. If you wanted to write a script, you could actually determine the dependency order by looking for exported and imported symbol names from an "nm" of all the .a files, and then breaking them out, and then sorting them properly ("man tsort"). If you want to do it manually, then nm all the .a files to .nm files of the same name, and then link try your link. When it fails, use the .nm files to grep for the undefined symbol, then add it after the inclusion of the library in which it is undefined on the link command line. Repeat until all errors are resolved. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message