2
votes

I've installed gfortran through the MinGW-get installer. I'm facing issues when I call a subroutine in Fortran and try to compile. I have written a small program Hello.F and a subroutine World.F such that program Hello.F calls Subroutine World.F

When I compile Hello.f using the command gfortran Hello.F I see an error as below,

Undefined Reference to 'World_'

collect2.exe: error: Id returned 1 exit status

Below is Hello.F,

PROGRAM HELLO
CALL WORLD
STOP
END

Below is World.F

SUBROUTINE WORLD
print *, "Hello World!"
RETURN
END

Both programs Hello.F and World.F reside in the same folder and I cd to this folder before typing in the command gfortran hello.f to compile the program.

1
Please use fortran for all Fortran questions. - Vladimir F
I suggest you to find some good textbook or tutorial from this century for your beginnings. You are programming in a 40 years old style which should be forgotten. Learn particularly about Fortran 95, free form source and other more recent stuff (25 years old). Learn about line indentation and why you do not need all the RETURN and STOP. - Vladimir F

1 Answers

0
votes

You may want to read up a bit here:

https://gcc.gnu.org/wiki/GFortranUsage

Specifically, you need to tell the compiler about all your files, for instance like this:

gfortran -o executable source1.f90 source2.f90

Or in your case:

gfortran -o helloworld Hello.F World.F