macos - gfortran : fatal error: no input files compilation terminated

标签 macos bash shell fortran

我最近开始在 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/

相关文章:

linux - 如何用另一个文件中的内容替换一个文件中第 XX 行之后的所有行?

iphone - 拍摄当前 Photoshop 文件的快照

macos - 在 Mac 上以伪分布式模式设置 Hadoop

python - 为 Python 3 mac 安装 PyQt4

linux - BASH - 从管道中出现的奇怪字符

json - 搜索 JSON 文件 bash

linux - 遍历文件并解析占位符变量

c - 如何在仍显示屏幕的同时将所有输出保存到屏幕上?

macos - 粘贴到新工作表后删除选择,粘贴到列中的第一个可用单元格

bash - 如何将存储在变量上的参数传递给 WGET