一般来说,CentOS 默认系统里是不带 Fortran 编译器(gfortran)的,所以“运行时缺少 Fortran”通常有两种理解,我分开说一下:
CentOS 最小化安装或服务器版 不会默认安装 gfortran。
gfortran --version
如果提示 command not found,说明没装。
# CentOS 7
sudo yum install gcc-gfortran
# CentOS 8 / Stream
sudo dnf install gcc-gfortran
安装后就能编译 .f90 / .f / .for 文件了。
如果是别人编译好的 Fortran 程序,运行时报错,比如:
error while loading shared libraries: libgfortran.so.5
这说明 缺少 Fortran 运行库,不一定需要编译器,只需要运行库:
# CentOS 7
sudo yum install libgfortran
# CentOS 8 / Stream
sudo dnf install libgfortran
gcc/g++ 有时默认有,但 gfortran 一般没有| 场景 | 是否缺 Fortran |
|---|---|
| 编译 Fortran 代码 | ✅ 缺 gfortran |
| 运行 Fortran 程序 | ✅ 可能缺 libgfortran |
| 普通 Web / 服务程序 | ❌ 一般不需要 |
如果你方便的话,可以把具体报错信息贴出来,我可以直接帮你判断是编译器问题还是运行库问题。