This is the mail archive of the gcc@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: linking c code against fortran libraries


On Wednesday 28 January 2004 5:24 pm, Craig Maloney wrote:
> Hi all.
>
> I have some questions about linking c code against fortran libraries.
> Suppose I have a code foo.c which calls routines in a fortran library
> libfortlib.
>
> First question:
> is
> g77  foo.o -lfortlib
> equivalent to
> gcc foo.o -lfortlib -lfrtbegin -lg2c -lm -shared-libgcc
>
> or does it actually matter that the compiler was invoked as g77.
>
> At any rate, neither of these is successful and give equivalent error:
> gcc-3.2.1/i686-pc-linux-gnu/libf2c/libF77/main.c: undefined reference to
> `MAIN__'
>
> It was my understanding that linking with g77 was supposed to tie up the
> stuff so that the entry point into the executable was somewhere in
> libfrtbegin which then called foo.o:main() after libg2c initialization.

No. libfrtbegin provides a main() function. This then calls the fortran 
PROGRAM unit (called MAIN__ internally).

You have three options:

- Don't link libfrtbegin, and provide a C main(). The link you quoted 
describes the things you need to do to ensure the Fortran runtime operates 
correctly.
- Link libftrbegin, and rename your C program entry point to MAIN__
- Link libftrbegin, and write your program entry point in Fortran.

Depending which you choose you may need to make sure you get the commanline 
arguments in the correct order.

> http://gcc.gnu.org/onlinedocs/gcc-3.3.2/g77/Startup-Code.html#Startup%20Code 

This seems reasonably accurate, it just doesn't mantion that the libg2c main() 
is actually in libfrtbegin.

Paul


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