This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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: Linking order fun


Hello Dennis, Arjen,

* Arjen Markus wrote on Mon, Nov 17, 2008 at 04:19:16PM CET:
> Dennis Wassel wrote:
>
>> I'm having "fun" with the linking order of my object code and
>> gfortran's libraries.
>> I have put the object code of my PROGRAM and lots of other stuff into
>> a static library, say libfoo.a. Now I want to have gfortran glue it
>> all together to create an executable. Doing that results in
>>
>> libgfortranbegin.a(fmain.o): In function `main':
>> libgfortran/fmain.c:21: undefined reference to `MAIN__'
>> collect2: ld returned 1 exit status
>>
>> although there clearly is a T  MAIN__ in libfoo.a.
>> Ok, so I tell gfortran to be more --verbose about its doings. I see
>> that -lgfortranbegin is issued *after* my libfoo.a, so the linker does
>> not pull MAIN__ from libfoo. Taking the (massive) link command and
>> putting -lgfortranbegin in front of all the linkable stuff works, but
>> this is quite cumbersome.

With GNU binutils ld, you could use
  -Wl,--whole-archive libfoo.a -Wl,--no-whole-archive

Of course that will pull in all of libfoo.a, but that seems desirable in
this situation.

Please Cc: me on replies.

Cheers,
Ralf


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