This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: *.f *.c linking problem - g77 = gcc (options)?
- To: htl10 at cus dot cam dot ac dot uk
- Subject: Re: *.f *.c linking problem - g77 = gcc (options)?
- From: Craig Burley <burley at gnu dot org>
- Date: Mon, 13 Jul 1998 16:58:36 -0400 (EDT)
- CC: egcs-bugs at cygnus dot com
>For a very strange reason, somebody whose code on SunSparc I am tryng to
>port to linux decided to have fortran routines, but a c main program
>wrapper and some c routines.
>
>So on Sunsparc he was doing something like:
>
>f77 src/routine1.f -c -o obj/routine1.o
>cc src/routine2.c -c -o obj/routine2.o
>cc src/wrapper.c -c -o obj/wrapper.o
> -----where wrapper.c contains a main() routine
>f77 -o result-binary obj/*.o -llib1 -llib2
>
>This does not work for egcs g77 since libf2c contains main.o also. I was
>able to compile the binary by striping main.o from libf2c.a with "ar" (for
>a day). I.e. It will compile with a broken libf2c.a in which main.o is
>removed.
>
>So I am thinking of keeping a broken version of libf2c.a (called it
>"libf2c_broken.a", and do a
>
>"gcc -lf2c_broken -l...." instead of g77. So what does g77 correponds to,
>expanding to gcc lines?
Normally "g77 foo.f" becomes "gcc foo.f -lf2c -lm" in egcs version 1.0.
`-l' options other than `-lf2c' and `-lm' are treated basically like
source file names. Some of this is improved in egcs 1.1 (now being
tested), and many of the improvements are already in g77 0.5.23,
the rest to come in g77 0.5.24.
>I think this qualifies as a "bug" of at least a missing desirable quality
>of egcs gcc/g77 - if the sun cc/f77 compiler can do it, egcs gcc/g77
>should be...
We've recently addressed this deficiency in egcs, and also in g77 0.5.23,
which is already released (and based on gcc 2.8.1, not on egcs).
What libf2c (renamed libg2c for egcs 1.1, in testing now, and g77 0.5.23)
has is still a main() entry point, but it's a much simpler routine
that calls "helper" routines that you can call yourself from your
C code, if you like.
In particular, this fixes the problem whereby GETARG or IARGC was
called in Fortran code (compiled by g77 or f2c), which caused the
linker to try and link in `xargc' and `xargv' globals, which in
turn were defined only in libf2c's main.o object file.
Whether it fixes your particular problem, I don't know -- "this does
not work" doesn't provide much info -- but it should provide a
better basis for you to address the problems you are seeing.
So, wait for egcs 1.1 and upgrade to that; or obtain an egcs snapshot
and either use it or apply just the relevant differences to your own
copy of egcs (the latter requires some compiler/library programming
experience, but it's not too hard); or switch to g77 0.5.23 and gcc 2.8.1
for now, until egcs 1.1 comes out.
The long-term fix is to eliminate the kludge whereby a Fortran
main program is compiled as MAIN__ instead of main, along with
the main.o entry in the library, entirely. That probably won't
happen until it is part of the libg77 project.
For more info on g77 issues like this, start by reviewing the g77
docs and also check out:
<ftp://alpha.gnu.org/g77.plan>
tq vm, (burley)