【发布时间】:2022-01-07 09:54:54
【问题描述】:
我正在尝试运行我团队的一些旧的 fortran 代码。
- 我有两个 Fortran 77 代码(
cklib.f和grcom.f),我使用 fort77 编译并获得了两个目标文件。 - 我有两个 Fortran 90 代码(
write_counterflow_sol.f和read_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 -v或f77 --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 specified和f77 --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