温馨提示×

ubuntu编译fortran用什么工具

小樊
48
2026-10-07 03:39:54
栏目: 智能运维

在 Ubuntu 上编译 Fortran 程序,常用以下几种工具/编译器:

1. GNU Fortran(gfortran) ✅ 最常用、免费、开源

  • 安装:
    sudo apt update
    sudo apt install gfortran
    
  • 使用:
    gfortran hello.f90 -o hello
    ./hello
    

2. Intel Fortran Compiler(ifort / ifx)

  • 性能优化好,适合科学计算
  • 可通过 Intel oneAPI 安装:
    # 示例(需先注册/下载 oneAPI)
    sudo apt install intel-oneapi-compiler-fortran
    
  • 使用:
    ifort hello.f90 -o hello
    # 或新版
    ifx hello.f90 -o hello
    

3. Flang(LLVM Fortran)

  • 基于 LLVM 的 Fortran 编译器
  • 安装:
    sudo apt install flang
    
  • 使用:
    flang hello.f90 -o hello
    

4. 构建工具(推荐配合使用)

  • Make
    sudo apt install make
    
  • CMake
    sudo apt install cmake
    

推荐选择

场景 推荐
学习 / 普通使用 ✅ gfortran
高性能计算 Intel ifort/ifx
研究 LLVM 生态 Flang

如果你是刚开始学 Fortran,直接用 gfortran + make 就足够了。需要我给你一个完整示例吗?

0 踩