This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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: compilation problem: undefined reference


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


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