用2个编译器编译fortran程序

问题描述 投票:0回答:1

我正在尝试运行一个用 fortran 编写的程序,其中子例程已使用 gfortran 编译,主程序已使用 ifort 编译:

这里是源代码:

子程序:

subroutine testsub
    implicit none
    integer icarte
    read(10,*) icarte
    write(*,*)icarte 
    return 
    end`

主要代码:

program test
    implicit none
    integer i
    open (unit=10, file="file_test")
    do i=1,6
       read(10,*)
    enddo
    call testsub
    close(10)
    end

读取的文件为:

1
2
3
4
5
6
7 5 6 8
23

然后我这样编译:

gfortran -c testsub.f

ar rcs libtest.a testsub.o

ifort -o testexe test.f -L./ -ltest -L/.../gcc/4.7.1/lib64 -lgfortran

我得到了:

At line 4 of file testsub.f (unit = 10, file = 'fort.10')
Fortran runtime error: End of file

看起来逻辑单元没有赋予子程序。 我应该在某处添加一个编译选项...但我真的不知道什么以及在哪里... 并回答“如果我使用相同的编译器编译这两个文件会发生什么?”的问题。 : 程序运行完美:)

所以如果有人有任何想法......

fortran intel-fortran
1个回答
5
投票

这行不通。当您在主程序中打开文件时,ifort 库内部的某个位置将打开该文件并存储与其相关的一些状态。 GFortran 对 ifort 运行时库的内部状态一无所知,并尝试在其自己的运行时库状态中查找该单元,这显然失败了。

© www.soinside.com 2019 - 2024. All rights reserved.