Trouble with cc/f77

Charles Geyer geyer at aylmer.uchicago.edu
Sun Feb 24 09:13:31 AEST 1991


[I missed the beginning of the thread, I hope these attributions are correct]

In article <1991Jan24.001055.3069 at ims.alaska.edu Don Rice
(fnddr at acad3.alaska.edu) writes:

> A couple of cc/f77 problems have turned up (Ultrix 4.0/DS5000/Fortran 2.1)....
> ... when trying to combine a main program written in C with a subroutine
> written in Fortran, the Fortran built-in functions aren't found:
>   > cc -o prog main.c fortsub.o -lF77 -lU77 -lI77 -lm
>   ld:
>   Undefined:
>   sinf
>   cosf
>   sqrtf

In article <1991Jan24.194343.5054 at morrow.stanford.edu> farrell at tioga.Stanford.EDU (Phil Farrell) replies:

> Is the C compiler even finding the libraries?  As installed, Fortran 2.1
> libraries are in /usr/lib/cmplrs/f77, but the C compiler looks for 
> those -lF77 etc directives in /usr/lib.  I created symbolic links
> for libF77.a, libI77.a, and libU77.a from /usr/lib/cmplrs/f77 to /usr/lib
> on my system to address this problem.
>
> Secondly, you realize that the linker only searches a library once for 
> any references on its current "unresolved" list.  If a routine from one
> library calls one from another library that has already been searched, 
> that will created an undefined reference.  You might play with the 
> order of libraries on your command line, or even add another -l command
> at the end to search the library a second time.

My solution to this problem is the following

LDFLAGS = -L/usr/lib/cmplrs/f77
LIBS = -lF77 -lI77 -lU77 -lm
OBJS = prog.o foo.o baz.o

prog : $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

My question is this: What is the "offical" right way to do this, if any?
Is there something in the DEC manuals about calling Fortran from C?

Please don't tell me to rtfm, this is a Sun-only site here.  I am trying to
solve some problems for a friend and get myself ready for a move to a
DEC-only site in September.

Charles Geyer
Department of Statistics
University of Chicago
geyer at galton.uchicago.edu



More information about the Comp.unix.ultrix mailing list