gfortran:致命错误:没有输入文件编译终止



我最近开始在Mac OS X 10.6.8上用gfortran用Fortran编程。我编写了以下简单的.f90程序:

sayhi.f90:

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

main.f90:

program main
  implicit none
  call sayhi()
end program

当我在终端中键入以下命令时,程序将按预期编译:

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

但是,当我尝试使用bash脚本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

并在终端中键入

bash ./helloworld.sh

返回以下错误:

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

我确信gfortran安装正确,因为直接在Terminal中输入命令可以很好地工作,并且上面提到的所有.f90.sh文件都在同一个目录中,这就是我现在的工作目录。即使我不使用变量F90,而是直接在shell文件中使用gfortran命令,也会出现同样的no input files问题。

有人能帮我找出问题出在哪里吗?非常感谢!

分配变量时,不能在=符号之间添加空格。

F90= gfortran

应该是

F90=gfortran

更改

# Note: no space before equal sign
F90= gfortran

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

最新更新