我是Fortran的初学者,运行Fortran编写的模型。当我试图编译它时,我得到了如下的错误消息:
libtool: link: (cd ".libs" && rm -f "libgrib_api_f77.so" && ln -s "libgrib_api_f77.so.1.0.0" "libgrib_api_f77.so")
libtool: link: ar cru .libs/libgrib_api_f77.a grib_fortran.o grib_f77.o
libtool: link: ranlib .libs/libgrib_api_f77.a
libtool: link: ( cd ".libs" && rm -f "libgrib_api_f77.la" && ln -s "../libgrib_api_f77.la" "libgrib_api_f77.la" )
gfortran -c -o same_int_long.o same_int_long.f90
same_int_long.f90:23:18:
17 | call check_long(x2(1),x2(2),ret)
| 2
......
23 | call check_long(x4(1),x4(2),ret)
| 1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/INTEGER(2)).
same_int_long.f90:29:18:
17 | call check_long(x2(1),x2(2),ret)
| 2
......
29 | call check_long(x8(1),x8(2),ret)
| 1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(8)/INTEGER(2)).
same_int_long.f90:51:17:
45 | call check_int(x2(1),x2(2),ret)
| 2
......
51 | call check_int(x4(1),x4(2),ret)
| 1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/INTEGER(2)).
same_int_long.f90:57:17:
45 | call check_int(x2(1),x2(2),ret)
| 2
......
57 | call check_int(x8(1),x8(2),ret)
| 1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(8)/INTEGER(2)).
make[2]: *** [Makefile:546: same_int_long.o] Error 1
make[2]: Leaving directory '/gpfs/home3/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source/fortran'
make[1]: *** [Makefile:604: all-recursive] Error 1
make[1]: Leaving directory '/gpfs/home3/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source'
make: *** [Makefile:398: /home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source-LXgfortran/include/grib_api.mod] Error 2
我所做的基本上是遵循模型的安装:
Step1
(base) [eccei339@int3 ~]$ mkdir snellius_surfex
(base) [eccei339@int3 ~]$ cp open_surfex_v8_1_20200107.tar-2.gz snellius_surfex/
(base) [eccei339@int3 ~]$ cd snellius_surfex/
(base) [eccei339@int3 snellius_surfex]$ tar zxvf open_surfex_v8_1_20200107.tar-2.gz
…(省略tar ZXVF日志信息)
步骤2:一些重要的环境变量
(base) [eccei339@int3 snellius_surfex]$ export VER_MPI="NOMPI"
(base) [eccei339@int3 snellius_surfex]$ export OMP_NUM_THREADS=1
(base) [eccei339@int3 snellius_surfex]$ module load 2021
(base) [eccei339@int3 snellius_surfex]$ module load GCC/10.3.0
(base) [eccei339@int3 snellius_surfex]$ ls
open_SURFEX_V8_1 open_surfex_v8_1_20200107.tar-2.gz
(这里我按照软件的安装说明导出了一些必要的环境变量)
步骤3:配置
(base) [eccei339@int3 snellius_surfex]$ cd open_SURFEX_V8_1/src/
(base) [eccei339@int3 src]$ ls
ASSIM Makefile Rules.bullXI15.mk Rules.MCgfortran.mk SURFEX
configure Makefile.SURFEX.mk Rules.bullXI16.mk Rules.SX8.mk
FORC OFFLIN Rules.LXgfortran.mk Rules.zgfortran.mk
include Rules.AIX64.mk Rules.LXifort.mk Rules.zifort.mk
LIB Rules.bgfortran.mk Rules.LXpgi.mk scripts
(base) [eccei339@int3 src]$ ./configure
(省略" configure "命令的长日志信息)
(base) [eccei339@int3 src]$ . ../conf/profile_surfex-LXgfortran-SFX-V8-1-1-NOMPI-OMP-O2-X0
(软件安装过程中必不可少的步骤)
步骤4:制作母版
(base) [eccei339@int3 src]$ make
find: ‘/home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/dir_obj-LXgfortran-SFX-V8-1-1-NOMPI-OMP-O2-X0/MASTER’: No such file or directory
cd /home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source && LDFLAGS= FCFLAGS= CPPFLAGS=""
./configure --disable-jpeg --prefix=/home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source-LXgfortran FC="gfortran" &&
make -j 1 clean &&
make -j 1 &&
make -j 1 install &&
make -j 1 clean
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
(省略长日志信息,最后几行是问题描述开头显示的错误信息)
我搜索了互联网,这可能是由于GCC 10比旧的GCC更严格(我去年用旧的GCC编译了这个模型,但这次失败了,因为我们的服务器转移到一个新系统,因此GCC从旧版本升级到新版本)。来自Google的一些信息告诉我可以添加如下内容:
export FCFLAGS="-w -fallow-argument-mismatch -O2"
export FFLAGS="-w -fallow-argument-mismatch -O2"
但是我在第2步中尝试了它,在那里我导出了一些必要的环境变量,它仍然不起作用。所以我想知道有没有人可以帮助我?非常感谢!
更新:来自http://distfiles.macports.org/grib_api/的grib_api-1.17.0-Source/fortran/same_int_long.f90
源代码如下:
! Copyright 2005-2016 ECMWF.
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
!
! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
integer function kind_of_long()
integer(2), dimension(2) :: x2 = (/1, 2/)
integer(4), dimension(2) :: x4 = (/1, 2/)
integer(8), dimension(2) :: x8 = (/1, 2/)
character(len=1) :: ret
kind_of_long=-1
call check_long(x2(1),x2(2),ret)
if (ret == 't') then
kind_of_long=2
return
endif
call check_long(x4(1),x4(2),ret)
if (ret == 't') then
kind_of_long=4
return
endif
call check_long(x8(1),x8(2),ret)
if (ret == 't') then
kind_of_long=8
return
endif
end function kind_of_long
integer function kind_of_int()
integer(2), dimension(2) :: x2 = (/1, 2/)
integer(4), dimension(2) :: x4 = (/1, 2/)
integer(8), dimension(2) :: x8 = (/1, 2/)
character(len=1) :: ret
kind_of_int=-1
call check_int(x2(1),x2(2),ret)
if (ret == 't') then
kind_of_int=2
return
endif
call check_int(x4(1),x4(2),ret)
if (ret == 't') then
kind_of_int=4
return
endif
call check_int(x8(1),x8(2),ret)
if (ret == 't') then
kind_of_int=8
return
endif
end function kind_of_int
program same_int_long
integer ki,kl
ki=kind_of_int()
kl=kind_of_long()
if (ki /= kl) then
write (*,'(i1)') 0
else
write (*,'(i1)') 1
endif
end program same_int_long
以下是make
的完整日志信息:https://drive.google.com/file/d/14rkj2ay39Rv84QBL6UDiSdlIAfhuEt_z/view?usp=sharing
这种情况发生在我使用MPI fortran代码时。原因是gcc开发人员对什么应该是"好接口"的决定。在我的例子中有两个解决方案:
- 告诉gfortran忽略选项
-fallow-argument-mismatch
。 - 使用现代fortran接口(
use mpi
代替include mpif.h
)我选择了后者。
您实例化为INTEGER的内容正在获取由另一个(变量或声明)整数分配的值,该整数为不同的'字节';内存容量.例如,在其他语言中,int是4字节,而long是8字节。(注)Fortran也有类似C/c++的指针https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vna5/index.html注意:您没有显示有问题的代码,在源文件same_int_long中的第29行char 18左右。法郎? ?