This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: compilation problem: undefined reference
- From: Tobias Burnus <burnus at net-b dot de>
- To: ppanta <ppanta9 at hotmail dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Wed, 01 Aug 2007 10:20:33 +0200
- Subject: Re: compilation problem: undefined reference
- References: <11941374.post@talk.nabble.com>
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