【问题标题】:Is there any common Fortran compiler for both f77 and f90 codes是否有适用于 f77 和 f90 代码的通用 Fortran 编译器
【发布时间】:2022-01-07 09:54:54
【问题描述】:

我正在尝试运行我团队的一些旧的 fortran 代码。

  1. 我有两个 Fortran 77 代码(cklib.fgrcom.f),我使用 fort77 编译并获得了两个目标文件。
  2. 我有两个 Fortran 90 代码(write_counterflow_sol.fread_counterflow_sol.f),我使用 gfortran 编译并获得了另外两个目标文件。

现在,使用下面的 makefile,我正在尝试创建一个名为 remail.e 的可执行文件

SOURCE_CHEMKIN = ../CHEMKIN/DATA_BASES/SOURCES
SOURCE_APPLI= ../SOURCES_COUNTERFLOW/
SOURCES_f77 = $(SOURCE_CHEMKIN)cklib.f $(SOURCE_APPLI)grcom.f $(SOURCE_APPLI)write_counterflow_sol.f $(SOURCE_APPLI)read_counterflow_sol.f
TARGET = remail.e
OBJECTS =  $(SOURCES_f77:.f=.o)
COMPILE = f90
.f90.o :
    $(COMPILE) -o $*.o -c $*.f90
.f.o :
    $(COMPILE) -o $*.o -c $*.f
$(TARGET) : $(OBJECTS)
$(COMPILE)  $(OBJECTS) -o $@
del :
$(DELETE) $(OBJECTS)

但最终出现以下错误,

make: f90: Command not found
make: *** [remail.e] Error 127

我知道我的系统中没有 f90 编译器,因此我尝试在 makefile 中使用 COMPILE=gfortran 而不是 COMPILE=f90,结果出现此错误。

gfortran  ../CHEMKIN/DATA_BASES/SOURCES/cklib.o ../SOURCES_COUNTERFLOW/grcom.o ../SOURCES_COUNTERFLOW/write_counterflow_sol.o ../SOURCES_COUNTERFLOW/read_counterflow_sol.o -o remail.e
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start': 
(.text+0x20): undefined reference to `main'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckcomp_':
fort77-27216-1.c:(.text+0x3a4a): undefined reference to `s_cmp'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckcpml_':
fort77-27216-1.c:(.text+0x3eb8): undefined reference to `pow_di'
fort77-27216-1.c:(.text+0x476f): undefined reference to `s_wsle'
fort77-27216-1.c:(.text+0x4788): undefined reference to `do_lio'
fort77-27216-1.c:(.text+0x478d): undefined reference to `e_wsle'
../CHEMKIN/DATA_BASES/SOURCES/cklib.o: In function `ckrat_':
fort77-27216-1.c:(.text+0xfac0): undefined reference to `pow_dd'
fort77-27216-1.c:(.text+0xfb17): undefined reference to `pow_dd'
fort77-27216-1.c:(.text+0xfef5): undefined reference to `pow_di'
../SOURCES_COUNTERFLOW/grcom.o: In function `MAIN__':
fort77-27073-1.c:(.text+0x1d): undefined reference to `s_copy'
fort77-27073-1.c:(.text+0x36): undefined reference to `s_copy'
fort77-27073-1.c:(.text+0x13e): undefined reference to `s_wsle' 
../SOURCES_COUNTERFLOW/write_counterflow_sol.o: In function `write_counterflow_sol__':
fort77-27083-1.c:(.text+0x85): undefined reference to `f_open'
fort77-27083-1.c:(.text+0xc0): undefined reference to `s_wsfe'
fort77-27083-1.c:(.text+0xd6): undefined reference to `do_fio'
../SOURCES_COUNTERFLOW/read_counterflow_sol.o: In function `read_counterflow_sol__':
fort77-28808-1.c:(.text+0x85): undefined reference to `f_open'
fort77-28808-1.c:(.text+0x9b): undefined reference to `s_rsfe'
fort77-28808-1.c:(.text+0xb1): undefined reference to `do_fio'
collect2: error: ld returned 1 exit status
make: *** [remail.e] Error 1

我还尝试在 makefile 中使用 COMPILE=f77 并成功执行,但是当我运行可执行文件时出现以下错误。

fmt: end of file
apparent state: unit 14 named sol2
last format: (3i10)
lately reading sequential formatted external IO
Aborted (core dumped)

f77 -v 的输出如下,

/usr/bin/f77: fort77 Version 1.15
/usr/bin/f77: No input files specified

f77 --version 的输出如下,

/usr/bin/f77: Illegal option: --version

type f77 的输出如下,

f77 is hashed (/usr/bin/f77)

抱歉,帖子太长了。但我们感谢您提供任何帮助。

【问题讨论】:

  • f77 很可能是相同的gfortran,您也可以通过调用gfortran 来调用它。 f77 -vf77 --version 打印什么?
  • stackoverflow.com/questions/66855252/…undefined reference to `main'表示你没有主program。其他未定义的引用是对您缺少的某些子例程或函数的调用。
  • @VladimirF, f77 -v 打印 /usr/bin/f77: fort77 Version 1.15 /usr/bin/f77: No input files specifiedf77 --version 打印 /usr/bin/f77: Illegal option: --version
  • 好的,所以它实际上是f2c。一个非常非常过时的东西。问题是你只能为 Fortran 77 代码使用这个,但如果你还需要使用 Fortran 90,它对你来说没用。您不能将它与像 gfortran 这样的 Fortran 90 编译器结合使用。 可能有一些选项可以解决您当前看到的名称修改问题,但正如 janneb 所提到的,这不是这种组合的最后一个问题的可能性非常高。
  • 另请注意,您的 Makefile 中的 f77 不必与您当前拥有的 f77 相同。它可能是任何其他编译器。它可能是 Solaris 上的 Sun 编译器,也可能是指向其他任何东西的符号链接,就像您的 f77 实际上是 fort77,它是重新打包的 f2c。例如,在我的计算机上,f77 实际上是 Oracle 编译器,是 Sun 编译器的继承者,现在实际上只是 f90 的包装器,与 sunf90 相同。

标签: fortran executable


【解决方案1】:

Gfortran 支持 Fortran 90,它是 Fortran 77 的超集。Gfortran 还支持在 Fortran 90 之前常用的几种流行语言扩展。

由于不同的运行时库和不同的 ABI,尝试使用多个不同的编译器来编译单个应用程序可能会导致问题。

所以,忘记 fort77 和 g77 以及其他过时的编译器吧。

【讨论】:

  • 几乎是一个超集。
  • @francescalus 考虑到 OP 似乎对 Fortran 编程有多么困惑,我认为最好不要因一些极端情况而陷入迂腐。但是,是的,严格来说你当然是正确的。
  • @janneb,感谢您的回答。很清楚!!
【解决方案2】:

所以要具体一点。您在帖子中看到的大多数当前错误都来自缺少的 fort77 运行时库。您使用f77 编译的代码将其openreadwrite、...语句转换为对运行时库中用C 实现的函数的调用。例如,f_open 在调用 open 语句的地方被调用,pow_dd 函数被调用在像 a**b 这样的功能在 a 和 b 都是双精度时被调用,pow_di 用于a**i其中 i 是一个整数,依此类推。

这些函数与 gfortran 编译的代码不兼容。库的 I/O 部分不兼容。在fort77代码中打开的文件不能被readwrite在gfortran中使用,反之亦然。

可能可以通过链接运行时库来消除大部分错误消息。也许是-lf2c。但是,这并不意味着代码可以正常工作。在简单的情况下可能会,但一般情况下不会。

你真的应该用 gfortran 编译所有东西,就像 janneb 回答的那样。如果您的代码与 gfortran 不兼容,则很可能不符合标准,必须进行修复。

对于此类可能的修复的具体建议,您必须创建带有特定错误的问题,例如 How to solve the "fmt: end of file, last format: (3i10)" error? 但带有完整的 [mcve]。我们真的需要一个完整的代码,我们可以用它需要的所有必要数据进行测试。代码也必须相当短。请注意,隔离如此小的独立代码通常是一项艰巨的工作,但这是必要的。

【讨论】:

  • 非常感谢您的回答。现在,事情对我来说越来越清楚了。所以我要做的是卸载fort77并尝试使用gfortran编译和运行所有内容并解决途中的错误。再次感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-10
  • 1970-01-01
  • 1970-01-01
  • 2012-01-24
  • 1970-01-01
相关资源
最近更新 更多