在 Ubuntu 下配置 Fortran 开发环境,通常步骤如下:
Ubuntu 下最常用的 Fortran 编译器是 gfortran(GNU Fortran)。
sudo apt update
sudo apt install gfortran
gfortran --version
看到版本信息即表示安装成功。
nano hello.f90
内容示例(Fortran 90):
program hello
print *, "Hello, Fortran!"
end program hello
gfortran hello.f90 -o hello
./hello
gfortran test.f90 -o test \
-O2 \ # 优化
-Wall \ # 显示警告
-g \ # 调试信息
-fcheck=all # 运行时检查
示例 Makefile:
FC = gfortran
FLAGS = -O2 -Wall
test: test.f90
$(FC) $(FLAGS) test.f90 -o test
clean:
rm -f test
使用:
make
./test
make clean
需要安装 Intel oneAPI:
sudo apt install intel-oneapi-compiler-fortran
sudo apt install gdb
sudo apt install liblapack-dev libblas-dev
编译时链接:
gfortran main.f90 -llapack -lblas -o main
如果你有具体需求(如:科学计算、并行 MPI、老旧 Fortran 77 代码、与 C 混合编程等),可以告诉我,我可以给你更针对性的配置方案。