tvk
tvk

Reputation: 153

gfortran: fatal error: no input files compilation terminated

I am starting to program in Fortran with gfortran recently on Mac OS X 10.6.8. I wrote the following simple .f90 programs:

sayhi.f90:

subroutine sayhi()
  implicit none
  ! Display output to screen
  print*, 'Hello World'
end subroutine sayhi

and main.f90:

program main
  implicit none
  call sayhi()
end program

When I type the following command in Terminal, the program compiles as expected:

gfortran sayhi.f90 main.f90 -o helloworld.out

However, when I try to use a bash script helloworld.sh:

#!/bin/bash

# Set your compiler (ifort, gfortran, or g95)
# Note: no space before equal sign
F90= gfortran

# Clear old files
rm *.o

# Compile and link (note: variable is used via a $ sign)
$F90 sayhi.f90 main.f90 -o helloworld.out

and type in Terminal

bash ./helloworld.sh

the following error returns:

gfortran: fatal error: no input files
compilation terminated.
rm: *.o: No such file or directory
./helloworld.sh: line 11: sayhi.f90: command not found

I am sure that gfortran is properly installed, since directly inputing the command in Terminal works fine, and all the .f90 and .sh files mentioned above are in the same directory, which is my present working directory. Even if I refrain from using the variable F90 and use the gfortran command directly in the shell file, the same no input files problem occurs.

Could anyone help me identify what the problem is? Many thanks!

Upvotes: 2

Views: 8933

Answers (2)

konsolebox
konsolebox

Reputation: 75588

You can't add spaces around the = symbol between when assigning variables.

F90= gfortran

should be

F90=gfortran

Upvotes: 3

user000001
user000001

Reputation: 33387

Change

# Note: no space before equal sign
F90= gfortran

To

# Note: no space before OR AFTER the equal sign
F90=gfortran

Upvotes: 1

Related Questions