This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: command line order of object files and libraries


wjposer@ldc.upenn.edu (William J Poser) writes:

> I have always (since 1982) believed that when compiling C on *nix
> object files should precede libraries on the command line since
> the linker processes files in the same order and only loads
> library routines to which it has seen references at that point.
> This belief is supported by the Single Unix spec and by
> the current gcc info files (under "Link Options"),
> as well as other documents that I have been able to find,
> such as the Apple Developer docs for gcc.
> 
> Yesterday I tried to compile a program I encountered
> on Freshmeat where the link failed because the Makefile
> had the libraries before the object files. When I raised
> this with the author of the program, he said that I was
> only the second person in many years to encounter this
> problem and that he himself uses gcc on GNU/Linux and did
> not encounter it. I have heard that there are linkers
> that do not work this way, but do not recall ever actually
> encountering one, and am surprised to hear of this
> behavior with gcc on GNU/Linux.
> 
> Have I misunderstood the expected behavior of gcc?
> If not, can anyone explain why the author of the
> program in question describes such different
> behavior? Thanks.

This is a question about the linker, not about the compiler.  The
linker is part of the GNU binutils.  See
http://sourceware.org/binutils/.

You are correct in your description of how the GNU linker behaves: it
retains the order of object files and libraries, and the order
matters.  However, this is mostly only true when using .a archives.
When using .so shared libraries things work differently.  Perhaps the
GNU/Linux build uses shared libraries?

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]