3

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.

Giri
  • 33
  • 1
  • 4

1 Answers1

0

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

NichtJens
  • 1,709
  • 19
  • 27
  • Thanx so much, this one worked. but in my actual scenario I have 100s of subroutine files. Is there a way to automate this? – Giri Oct 17 '17 at 09:46
  • Great! The standard way of automatizing this is a Makefile. See here: https://stackoverflow.com/questions/5871780/creating-a-fortran-makefile – NichtJens Oct 17 '17 at 10:47