configure: error: The Fortran compiler gfortran will not compile files that call the same routine with arguments of different types.
时间: 2025-08-12 08:52:50 浏览: 4
<think>我们正在处理用户关于在配置编译WRF-Chem(或类似科学计算软件)时遇到的Fortran编译器(gfortran)兼容性错误。错误信息为:
"configure: error: The Fortran compiler gfortran will not compile files that call the same routine with arguments of different types."
根据引用[1],这个问题在安装mpich-3.0.4库时出现,并且用户已经尝试重装虚拟机多次未果。
### 问题分析
这个错误通常是由于较新版本的gfortran编译器(特别是gcc 10及以上版本)引入了更严格的类型检查(称为“类型安全”要求)导致的。在旧版本的MPICH(如3.0.4)中,存在一些Fortran代码调用了同一个子程序(routine)但使用了不同类型的参数,这在新的编译器标准下是不允许的。
### 解决方案
解决此问题有两种主要方法:
#### 方法1:降级gfortran编译器版本
安装较低版本的gfortran(例如gcc-9或gcc-8),然后重新配置MPICH。
**步骤:**
1. 添加旧的GCC版本仓库(如果系统没有自带):
```bash
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
```
2. 安装gcc-9和gfortran-9:
```bash
sudo apt install gcc-9 gfortran-9
```
3. 设置gcc-9和gfortran-9为默认编译器(使用`update-alternatives`):
```bash
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-9 90
```
4. 重新运行MPICH的配置脚本。
#### 方法2:升级MPICH版本
升级到更高版本的MPICH(如3.3以上),这些版本已经修复了类型不匹配的问题。
**步骤:**
1. 卸载当前安装的MPICH(如果已安装)。
2. 从MPICH官网下载最新稳定版(例如3.4.3):
```bash
wget http://www.mpich.org/static/downloads/3.4.3/mpich-3.4.3.tar.gz
tar -xvf mpich-3.4.3.tar.gz
cd mpich-3.4.3
```
3. 配置、编译和安装:
```bash
./configure --prefix=$DIR/mpich # $DIR为自定义安装路径
make -j 8
make install
```
4. 将MPICH的bin目录加入PATH环境变量(在~/.bashrc中添加):
```bash
export PATH=$DIR/mpich/bin:$PATH
source ~/.bashrc
```
#### 方法3:在配置时禁用Fortran(不推荐)
如果不需要Fortran接口,可以在配置MPICH时禁用Fortran:
```bash
./configure --disable-fortran
```
但WRF-Chem依赖Fortran,因此不推荐此方法。
### 验证解决方案
安装完成后,执行以下命令验证MPI安装:
```bash
mpiexec --version
```
### 注意事项
- 如果选择降级gfortran,请注意系统其他软件可能依赖新版本的编译器。
- 确保在编译WRF-Chem时,环境变量(如`PATH`、`LD_LIBRARY_PATH`)正确指向新安装的MPICH。
### 引用说明
根据引用[2],WRF-Chem依赖于WRF模型,因此确保MPICH等基础库正确安装至关重要。另外,引用[4]提到WRF-Chem已不再继续开发,但用户仍可使用现有版本。
### 相关问题
1. 如何检查当前系统中安装的gfortran版本?
2. 升级MPICH后如何确保WRF-Chem使用新的MPI库?
3. 在降级gfortran后,如何恢复使用系统默认的编译器版本?</think>### WRF-Chem 编译错误:Fortran 编译器类型不匹配问题解决方案
您在配置编译 WRFChem 时遇到的错误:
```bash
configure: error: The Fortran compiler gfortran will not compile files that call the same routine with arguments of different types
```
这是由较新版本的 gfortran(gcc 10+)引入的严格类型检查导致的,与 MPICH 库的兼容性问题有关[^1]。以下是系统性的解决方案:
---
### 方法一:降级 gfortran 编译器(推荐)
#### 步骤:
1. **安装旧版 gfortran**:
```bash
sudo apt-get install gcc-9 gfortran-9 # Ubuntu/Debian
# 或
sudo yum install gcc9 gcc-gfortran9 # CentOS/RHEL
```
2. **设置编译器别名**:
```bash
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-9 90
sudo update-alternatives --config gfortran # 选择版本9
```
3. **验证版本**:
```bash
gfortran --version # 应显示 9.x.x
```
4. **重新配置 MPICH**:
```bash
cd mpich-3.0.4
make distclean
./configure --prefix=$DIR/mpich
make
make install
```
---
### 方法二:升级 MPICH 版本
```bash
wget https://www.mpich.org/static/downloads/4.1.2/mpich-4.1.2.tar.gz
tar -xvf mpich-4.1.2.tar.gz
cd mpich-4.1.2
./configure --prefix=$DIR/mpich
make -j 8
make install
```
---
### 方法三:修改编译器标志(临时方案)
在配置时添加宽松类型检查标志:
```bash
export FFLAGS="-fallow-argument-mismatch"
export FCFLAGS="-fallow-argument-mismatch"
./configure --prefix=$DIR/mpich
```
> **注意**:此方法可能掩盖潜在的类型错误,仅作临时解决方案[^1]。
---
### 验证 MPI 安装
```bash
# 检查编译器链接
which mpif90 # 应显示 $DIR/mpich/bin/mpif90
# 测试简单 MPI 程序
mpiexec --version
```
---
### 关键注意事项
1. **环境一致性**:
- 确保 `PATH` 和 `LD_LIBRARY_PATH` 优先指向自定义安装的 MPICH:
```bash
export PATH=$DIR/mpich/bin:$PATH
export LD_LIBRARY_PATH=$DIR/mpich/lib:$LD_LIBRARY_PATH
```
2. **WRF-Chem 依赖关系**:
- MPICH 必须与 NetCDF 使用相同的 Fortran 编译器
- 重新编译所有依赖库(zlib, libpng, Jasper):
```bash
cd netcdf
make distclean
./configure --prefix=$DIR/netcdf
make install
```
3. **编译器兼容性矩阵**:
| WRF-Chem 版本 | 推荐 gfortran | 推荐 MPICH |
|---------------|---------------|------------|
| 4.x | 9.x | >4.0 |
| 3.x | 8.x | 3.3.x |
> 根据引用[2],WRF-Chem 对底层依赖非常敏感,建议使用经过验证的编译器组合[^2]。
---
阅读全文
相关推荐



















