Linux上Fortran开发环境搭建指南
一 安装编译器与基础工具
| 发行版 | 安装命令 |
|---|---|
| Ubuntu/Debian | sudo apt update && sudo apt install -y gfortran build-essential cmake git |
| CentOS/RHEL 7 | sudo yum groupinstall -y “Development Tools” && sudo yum install -y gcc gcc-c++ gfortran make cmake git |
| CentOS/RHEL 8+/Fedora | sudo dnf groupinstall -y “Development Tools” && sudo dnf install -y gcc gcc-c++ gfortran make cmake git |
二 编写与构建第一个程序
program hello
implicit none
print *, "Hello, Fortran!"
end program hello
cmake_minimum_required(VERSION 3.16)
project(Hello Fortran)
add_executable(hello hello.f90)
mkdir -p build && cd build
cmake -DCMAKE_Fortran_COMPILER=gfortran ..
make
./hello
三 可选组件与IDE
四 Intel 与 NVIDIA 工具链(可选)
五 常见问题与排错