This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: ld and .a file question


On 29/05/2010 08:51, Lal wrote:

> -bash-3.00$ nm test1.o
> 00000018 T fun1
> 00000000 T func2
> 0000002a T main
>          U printf

> -bash-3.00$ ar rvf lib.a test.o
> r - test.o
> -bash-3.00$ nm lib.a
> 
> test.o:
> 00000018 T fun1
> 00000000 T func2
> 0000002a T main
>          U printf
> -bash-3.00$
> -bash-3.00$ ld -r lib.a -o test1.o
> -bash-3.00$ nm test1.o
> -bash-3.00$
> 
> I expected test1.o (in 2nd iteration) to have the symbols, but it does not!

  See the documentation for the --whole-archive option.  Normally ld only
pulls in members from archive files when they supply symbols that are required
by undefined references in a .o file that is already present in the link.  See
also this section from the description of the -l option:

>      The linker will search an archive only once, at the location where
>      it is specified on the command line.  If the archive defines a
>      symbol which was undefined in some object which appeared before
>      the archive on the command line, the linker will include the
>      appropriate file(s) from the archive.  However, an undefined
>      symbol in an object appearing later on the command line will not
>      cause the linker to search the archive again.

    cheers,
      DaveK


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