在Ubuntu上配置Fortran开发工具链可按以下步骤进行:
-
安装基础开发工具
sudo apt update sudo apt install build-essential -
安装Fortran编译器
- 安装默认版本(gfortran):
sudo apt install gfortran - 安装特定版本(如gfortran-7):
sudo apt install gfortran-7 sudo update-alternatives --config gfortran # 切换版本
- 安装默认版本(gfortran):
-
配置环境变量(可选)
若需手动指定编译器路径,编辑~/.bashrc文件,添加:export PATH=/usr/bin/gfortran-7:$PATH # 替换为实际路径 source ~/.bashrc -
安装辅助工具(可选)
- Fortran程序包管理器(fpm):
wget https://github.com/fortran-lang/fpm/releases/download/v0.9.0/fpm-0.9.0-linux-x86_64.tar.gz tar -xzf fpm-0.9.0-linux-x86_64.tar.gz export PATH=$PATH:/path/to/fpm-0.9.0-linux-x86_64/bin # 临时路径 # 或编辑~/.bashrc永久生效 - 代码编辑器/IDE:
推荐Visual Studio Code,安装后需配置Fortran插件(如fortran-language-server)。
- Fortran程序包管理器(fpm):
-
验证安装
创建测试文件hello.f90:program hello print *, "Hello, Fortran!" end program hello编译并运行:
gfortran -o hello hello.f90 ./hello若输出“Hello, Fortran!”则配置成功。
说明:
- 以上步骤基于Ubuntu默认软件源,若需安装特定版本编译器,可能需要添加PPA源(如
ppa:ubuntu-toolchain-r/test)。 - 实际开发中可根据项目需求安装额外库(如LAPACK、FFTW等)。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/1387401.html