Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 May 2002 18:52:41 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Mikhail Teterin <mi+mx@aldan.algebra.com>
Cc:        questions@FreeBSD.org, current@FreeBSD.org
Subject:   Re: does the order of .a files matter?
Message-ID:  <3CD9D669.9175E309@mindspring.com>
References:  <200205082044.09459.mi%2Bmx@aldan.algebra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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<path> -l<library>, 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3CD9D669.9175E309>