我最近开始在 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已经正确安装,因为直接在终端中输入命令就可以正常工作,并且上面提到的所有.f90
和.sh
文件都在同一目录,这是我当前的工作目录。即使我不使用变量 F90
并直接在 shell 文件中使用 gfortran
命令,也会出现同样的无输入文件
问题。
谁能帮我找出问题所在吗?非常感谢!
最佳答案
分配变量时,不能在 =
符号周围添加空格。
F90= gfortran
应该是
F90=gfortran
关于macos - gfortran : fatal error: no input files compilation terminated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18579640/