compilation problem: undefined reference
Tobias Burnus
burnus@net-b.de
Wed Aug 1 08:20:00 GMT 2007
Hi,
ppanta wrote:
> I need some help with the compilation problem. I looked around the site and
> I didn't get a satisfactory clue to solving my problem .. or I didn't look
> good enough. Anyway, it seems to be missing some kind of library?
> I'm new with Fortran so please let me know what I need to include in my file
> as a header or option for compilation.
>
In general, it would help to know on which platform and with which
version of gfortran the problem occurs ("gfortran -v" shows this
information).
But in this special case I think I know what the problem is:
> CC= gcc
> %.o: %.F $(DEPS)
> $(CC) -c $< -o $@
> $(PROGRAM): $(OBJECTS)
> $(CC) -v $^ -o $@ -lm
>
You use "gcc" to compile the Fortran programs and not "gfortran". While
for the compilation it does not make a difference, for the linking it
does: "gfortran" links different/additionally libraries than "gcc". For
Fortran programs you should therefore use:
FC=gfortran
%.o: %.F $(DEPS)
$(FC) -c $< -o $@
$(PROGRAM): $(OBJECTS)
$(FC) -v $^ -o $@
(The "-lm" is not needed as its linking happens automatically when using
"gfortran".)
Tobias
More information about the Fortran
mailing list