Creating archive file with main

Nick Clifton nickc@redhat.com
Tue May 31 13:27:00 GMT 2011


Hi Ajay,

>>> Could I make an archive (.a) which includes the main?
>> Yes you can.
>
> But when I combine this archive (which now has a main) with another
> archive and then hope to create an executable out of it, the linker
> starts cribbing.
 >
> i.e. gcc 1.a 2.a -o out
> where 1.a has main complains of undefined references to crt.o

This does not happen for me:

   % cat main.c
   extern int foo (void);
   int main (void) { return foo (); }

   % cat foo.c
   int foo (void) { return 1; }

   % gcc -c main.c foo.c
   % ar crv libmain.a main.o
   % ar crv libfoo.a foo.o
   % gcc libmain.a libfoo.a
   % ./a.out
   % echo $status
   1

Can you put together a full demonstration of the problem that you are 
having ?

Cheers
   Nick



More information about the Binutils mailing list