ubuntu

Ubuntu下Fortran程序怎么运行

小樊
43
2025-04-17 14:24:08
栏目: 智能运维

在Ubuntu下运行Fortran程序,可以按照以下步骤进行:

安装Fortran编译器

首先,确保你的系统上已经安装了Fortran编译器。最常用的编译器是gfortran。你可以使用以下命令在Ubuntu上安装gfortran:

sudo apt update
sudo apt install gfortran

编写Fortran程序

使用文本编辑器(如nanovimgedit)创建一个新的Fortran源文件。例如,创建一个名为hello.f90的文件,并编写以下简单的Fortran代码:

program hello
    implicit none
    print *, 'Hello, World!'
end program hello

编译Fortran程序

在终端中,导航到包含hello.f90文件的目录,然后使用gfortran编译器编译它:

gfortran -o hello hello.f90

这将生成一个名为hello的可执行文件。

运行Fortran程序

在终端中,使用以下命令运行编译后的Fortran程序:

./hello

你应该会看到输出 Hello, World!

注意事项

通过以上步骤,你应该能够在Ubuntu上成功编译并运行Fortran程序。如果需要更高级的功能,可以考虑安装集成开发环境(IDE)如Visual Studio Code,并配置相应的Fortran插件。

0
看了该问题的人还看了