在 Debian 上管理 Fortran 项目的实用流程
一 环境准备与依赖管理
sudo apt update && sudo apt install -y gfortran build-essential,gfortran --version。apt search <关键词> 查找后再安装。二 构建方式与项目结构
gfortran hello.f90 -o hello;运行:./hello。gfortran -o app main.f90 mod1.f90 mod2.f90。FC=gfortran,FFLAGS=-O2 -g(优化与调试),SRCS=main.f90 utils.f90,OBJS=$(SRCS:.f90=.o),TARGET=my_app;链接阶段按需加入库(如 -lm)。fpm new my_project 创建项目;fpm build 构建;fpm run 运行;FPM 可自动处理模块依赖,适合中小型项目与库开发。-lmpi_f08(Fortran 2008 MPI 接口)。三 库与链接管理
sudo ldconfig 更新缓存。sudo ldconfig;或在运行前导出 LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH。gfortran -c -fPIC libexample.f90 -o libexample.ogfortran -shared libexample.o -o libexample.sosudo cp libexample.so /usr/local/lib && sudo ldconfig-l<name>(例如 -lm 链接数学库),并确保链接顺序正确。四 开发工具与 IDE
sudo apt install codeblocks 后创建项目、构建与运行。五 版本控制与持续集成
git init、git add .、git commit),便于协作与回溯。apt update && apt install -y gfortran build-essential,随后执行 fpm build 或 make 完成构建与测试,确保跨环境可复现。