Xu *_*han 2 linux fortran makefile gnu-make gfortran
我是 Fortran 初学者,正在运行 Fortran 编写的模型。当我尝试编译它时,我收到一条错误消息,如下所示:
\nlibtool: link: (cd ".libs" && rm -f "libgrib_api_f77.so" && ln -s "libgrib_api_f77.so.1.0.0" "libgrib_api_f77.so")\nlibtool: link: ar cru .libs/libgrib_api_f77.a grib_fortran.o grib_f77.o\nlibtool: link: ranlib .libs/libgrib_api_f77.a\nlibtool: link: ( cd ".libs" && rm -f "libgrib_api_f77.la" && ln -s "../libgrib_api_f77.la" "libgrib_api_f77.la" )\ngfortran -c -o same_int_long.o same_int_long.f90\nsame_int_long.f90:23:18:\n \n 17 | call check_long(x2(1),x2(2),ret)\n | 2\n......\n 23 | call check_long(x4(1),x4(2),ret)\n | 1\nError: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/INTEGER(2)).\nsame_int_long.f90:29:18:\n \n 17 | call check_long(x2(1),x2(2),ret)\n | 2\n......\n 29 | call check_long(x8(1),x8(2),ret)\n | 1\nError: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(8)/INTEGER(2)).\nsame_int_long.f90:51:17:\n \n 45 | call check_int(x2(1),x2(2),ret)\n | 2\n......\n 51 | call check_int(x4(1),x4(2),ret)\n | 1\nError: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/INTEGER(2)).\nsame_int_long.f90:57:17:\n \n 45 | call check_int(x2(1),x2(2),ret)\n | 2\n......\n 57 | call check_int(x8(1),x8(2),ret)\n | 1\nError: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(8)/INTEGER(2)).\nmake[2]: *** [Makefile:546: same_int_long.o] Error 1\nmake[2]: Leaving directory \'/gpfs/home3/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source/fortran\'\nmake[1]: *** [Makefile:604: all-recursive] Error 1\nmake[1]: Leaving directory \'/gpfs/home3/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source\'\nmake: *** [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\n
Run Code Online (Sandbox Code Playgroud)\n我所做的基本上是按照模型的安装进行的:
\n步骤1
\n(base) [eccei339@int3 ~]$ mkdir snellius_surfex\n(base) [eccei339@int3 ~]$ cp open_surfex_v8_1_20200107.tar-2.gz snellius_surfex/\n(base) [eccei339@int3 ~]$ cd snellius_surfex/\n(base) [eccei339@int3 snellius_surfex]$ tar zxvf open_surfex_v8_1_20200107.tar-2.gz\n
Run Code Online (Sandbox Code Playgroud)\n\xe2\x80\xa6(省略tar zxvf日志信息)
\n第2步:一些必要的环境变量
\n(base) [eccei339@int3 snellius_surfex]$ export VER_MPI="NOMPI"\n(base) [eccei339@int3 snellius_surfex]$ export OMP_NUM_THREADS=1\n(base) [eccei339@int3 snellius_surfex]$ module load 2021\n(base) [eccei339@int3 snellius_surfex]$ module load GCC/10.3.0\n(base) [eccei339@int3 snellius_surfex]$ ls\nopen_SURFEX_V8_1 open_surfex_v8_1_20200107.tar-2.gz\n
Run Code Online (Sandbox Code Playgroud)\n(这里我按照软件安装的说明导出了一些必要的环境变量)
\n第三步:配置
\n(base) [eccei339@int3 snellius_surfex]$ cd open_SURFEX_V8_1/src/\n(base) [eccei339@int3 src]$ ls\nASSIM Makefile Rules.bullXI15.mk Rules.MCgfortran.mk SURFEX\nconfigure Makefile.SURFEX.mk Rules.bullXI16.mk Rules.SX8.mk\nFORC OFFLIN Rules.LXgfortran.mk Rules.zgfortran.mk\ninclude Rules.AIX64.mk Rules.LXifort.mk Rules.zifort.mk\nLIB Rules.bgfortran.mk Rules.LXpgi.mk scripts\n(base) [eccei339@int3 src]$ ./configure\n
Run Code Online (Sandbox Code Playgroud)\n(省略 \xe2\x80\x9cconfigure\xe2\x80\x9d 命令的长日志记录信息)
\n(base) [eccei339@int3 src]$ . ../conf/profile_surfex-LXgfortran-SFX-V8-1-1-NOMPI-OMP-O2-X0\n
Run Code Online (Sandbox Code Playgroud)\n(遵循软件安装说明的重要步骤)
\n第四步:制作主人
\n(base) [eccei339@int3 src]$ make\nfind: \xe2\x80\x98/home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/dir_obj-LXgfortran-SFX-V8-1-1-NOMPI-OMP-O2-X0/MASTER\xe2\x80\x99: No such file or directory\ncd /home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source && LDFLAGS= FCFLAGS= CPPFLAGS="" \\\n ./configure --disable-jpeg --prefix=/home/eccei339/snellius_surfex/open_SURFEX_V8_1/src/LIB/grib_api-1.17.0-Source-LXgfortran FC="gfortran" && \\\n make -j 1 clean && \\\n make -j 1 && \\\n make -j 1 install && \\\n make -j 1 clean\nchecking build system type... x86_64-unknown-linux-gnu\nchecking host system type... x86_64-unknown-linux-gnu\nchecking how to print strings... printf\nchecking for gcc... gcc\nchecking whether the C compiler works... yes\nchecking for C compiler default output file name... a.out\nchecking for suffix of executables... \nchecking whether we are cross compiling... no\n
Run Code Online (Sandbox Code Playgroud)\n(省略长日志信息,最后几行是本问题描述开头显示的错误消息。)
\n我在网上搜索了一下,这可能是由于GCC 10比旧版GCC更严格(我去年用旧版GCC编译了这个模型并制作了它,但这次失败了,因为我们的服务器转移到了新系统,因此GCC从旧版本升级到新版本)。来自谷歌的一些信息说我可以添加这样的内容:
\nexport FCFLAGS="-w -fallow-argument-mismatch -O2"\nexport FFLAGS="-w -fallow-argument-mismatch -O2"\n
Run Code Online (Sandbox Code Playgroud)\n但我在步骤2中尝试了导出一些必要的环境变量,但仍然不起作用。所以我想知道有人可以帮助我吗?多谢!
\ngrib_api-1.17.0-Source/fortran/same_int_long.f90
更新:来自http://distfiles.macports.org/grib_api/的源代码如下:
! Copyright 2005-2016 ECMWF.\n!\n! This software is licensed under the terms of the Apache Licence Version 2.0\n! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.\n! \n! In applying this licence, ECMWF does not waive the privileges and immunities granted to it by\n! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.\n\ninteger function kind_of_long()\n integer(2), dimension(2) :: x2 = (/1, 2/)\n integer(4), dimension(2) :: x4 = (/1, 2/)\n integer(8), dimension(2) :: x8 = (/1, 2/)\n character(len=1) :: ret\n\n kind_of_long=-1\n\n call check_long(x2(1),x2(2),ret)\n if (ret == \'t\') then\n kind_of_long=2\n return\n endif\n\n call check_long(x4(1),x4(2),ret)\n if (ret == \'t\') then\n kind_of_long=4\n return\n endif\n\n call check_long(x8(1),x8(2),ret)\n if (ret == \'t\') then\n kind_of_long=8\n return\n endif\n\nend function kind_of_long\n\ninteger function kind_of_int()\n integer(2), dimension(2) :: x2 = (/1, 2/)\n integer(4), dimension(2) :: x4 = (/1, 2/)\n integer(8), dimension(2) :: x8 = (/1, 2/)\n character(len=1) :: ret\n\n kind_of_int=-1\n\n call check_int(x2(1),x2(2),ret)\n if (ret == \'t\') then\n kind_of_int=2\n return\n endif\n\n call check_int(x4(1),x4(2),ret)\n if (ret == \'t\') then\n kind_of_int=4\n return\n endif\n\n call check_int(x8(1),x8(2),ret)\n if (ret == \'t\') then\n kind_of_int=8\n return\n endif\n\nend function kind_of_int\n\nprogram same_int_long\n integer ki,kl\n\n ki=kind_of_int()\n kl=kind_of_long()\n if (ki /= kl) then\n write (*,\'(i1)\') 0\n else\n write (*,\'(i1)\') 1\n endif\nend program same_int_long\n\n\n
Run Code Online (Sandbox Code Playgroud)\n以下是完整的日志信息make
:https://drive.google.com/file/d/14rkj2ay39Rv84QBL6UDiSdlIAfhuEt_z/view ?usp=sharing
Mon*_*ger 11
我通过 MPI fortran 代码想到了这一点。原因是 gcc 开发人员对 \xc2\xabgood 接口\xc2\xbb 的决定,请参见此处。\n我的情况有两个解决方案:
\n-fallow-argument-mismatch
。use mpi
而不是include mpif.h
)\n我选择了后者。