Apologies to all who've replied... There *was* no main symbol in my foo.o because there was no main in foo.c (long story). Either of g77 foo.o -lfortlib or gcc foo.o -lfortlib -lfrtbegin -lg2c -lm -shared-libgcc link and run fine. Thanks again, Craig On Thu, 29 Jan 2004, Paul Brook wrote: > 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 >