[英]Is there any common Fortran compiler for both f77 and f90 codes
我正在嘗試運行我團隊的一些舊版 fortran 代碼。
cklib.f
和grcom.f
),我使用 fort77 編譯並獲得了兩個 object 文件。write_counterflow_sol.f
和read_counterflow_sol.f
),我使用 gfortran 編譯並獲得了另外兩個 object 文件。 現在,使用以下 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
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
的 output 給出以下內容,
/usr/bin/f77: fort77 Version 1.15
/usr/bin/f77: No input files specified
f77 --version
的 output 給出以下內容,
/usr/bin/f77: Illegal option: --version
type f77
的 output 給出以下信息,
f77 is hashed (/usr/bin/f77)
對不起,很長的帖子。 但任何幫助表示贊賞。
Gfortran 支持 Fortran 90,它是 Fortran 77 的超集。Gfortran 還支持在 Z843E353F7A5A6842B9206BF213DFEFE86Z 之前常用的幾種流行語言擴展。
由於不同的運行時庫和不同的 ABI,嘗試使用幾種不同的編譯器來編譯單個應用程序可能會導致問題。
所以,忘記 fort77 和 g77 以及其他過時的編譯器吧。
所以要具體一點。 您在帖子中看到的大多數當前錯誤都來自缺少的 fort77 運行時庫。 您使用f77
編譯的代碼將其open
、 read
、 write
…… 語句轉換為對運行時庫中 C 中實現的函數的調用。 例如,在調用open
語句時調用f_open
,調用pow_dd
function 當 a 和 b 都是雙精度時調用諸如a**b
之類的某些功能, pow_di
用於a**i
,其中 i 是 integer,等等。
這些函數與 gfortran 編譯的代碼不兼容。 庫的 I/O 部分不兼容。 在write
read
,反之亦然。
您可能可以通過鏈接運行時庫來消除大部分錯誤消息 go。 也許是-lf2c
。 但是,這並不意味着代碼可以正常工作。 在簡單的情況下可能會,但一般不會。
正如 janneb 回答的那樣,您真的應該使用gfortran
編譯所有內容。 如果您的代碼與 gfortran 不兼容,則很可能不符合標准,必須進行修復。
有關此類可能修復的具體建議,您必須創建帶有特定錯誤的問題,例如如何解決“fmt:文件結尾,最后格式:(3i10)”錯誤? 但有一個完整的 [mcve]。 我們真的需要一個完整的代碼,我們可以用它需要的所有必要數據進行測試。 代碼也必須相當短。 請注意,隔離如此小的獨立代碼通常是一項艱巨的工作,但這是必要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.