刚刚完成在 El Capitan 上安装 gfortran 6.1 编译器。接下来,我想知道如何运行文件。所以,我有几个问题:
- 保存文件应该使用哪个扩展名?是 .f90 还是其他扩展名?
- 可以使用哪种软件编辑和保存源代码?
- 保存文件后,如何编译它?是使用终端中的 gfortran 命令加上文件名(带路径)吗?在 Mac 上路径是什么样子的?
一个一步一步的指南会非常有帮助。我是第一次使用 Mac。 :)
刚刚完成在 El Capitan 上安装 gfortran 6.1 编译器。接下来,我想知道如何运行文件。所以,我有几个问题:
一个一步一步的指南会非常有帮助。我是第一次使用 Mac。 :)
gfortran /your/source/file
这是绝对路径。如果您已经在源文件所在的目录中,则不需要指定完整路径。逐步“hello world”:
Just to give a command line example without the need for an editor (this is not what you typically would do):
Open the terminal, then enter
cat >hello.f90 <<EOF
program hello
implicit none
write(*,*) 'hello world'
end program hello
EOF
Compile your program in the terminal with: gfortran hello.f90
./a.out
If you want another name use the -o
option:
gfortran -o hello hello.f90
./hello
./a.out
或 ./hello
命令的作用。这些命令应该在终端中执行,而且要在编译源文件的同一目录下执行(即可执行文件所在的位置)。 - d_1999