问题描述
我试图运行一个程序写在fortran其中子程序已编译gfortran和主程序已编译ifort:
这里的源代码:
子程序:
子程序testsub
implicit none
整数icarte
读取(10,*)icarte
写(*,*)icarte
return
end`
主代码:
程序测试
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
我获得:
在文件testsub的第4行。 f(单位= 10,文件='fort.10')
Fortran运行时错误:文件结束
$ b b
看起来逻辑单元没有给出子程序。
我应该在某处添加编译选项...但我真的不知道什么和在哪里...
并回答问题如果我用同一个编译器编译这两个文件会发生什么? 。 :
/ div>
这不会工作。当您在主程序中打开文件时,ifort库的某处将打开该文件,并将与其关联的某些状态存储。 GFortran对ifort运行时库的内部状态一无所知,并试图在其自己的运行时库状态中查找单元,这显然失败了。
I am trying to run a program wrote in fortran where the subroutine has been compiled with gfortran and the main program has been compiled with ifort:
Here the source code:
subroutine:
subroutine testsub
implicit none
integer icarte
read(10,*) icarte
write(*,*)icarte
return
end`
main code:
program test
implicit none
integer i
open (unit=10, file="file_test")
do i=1,6
read(10,*)
enddo
call testsub
close(10)
end
and the file read is:
1
2
3
4
5
6
7 5 6 8
23
And then I compile like that:
gfortran -c testsub.f
ar rcs libtest.a testsub.o
ifort -o testexe test.f -L./ -ltest -L/.../gcc/4.7.1/lib64 -lgfortran
and I obtained:
At line 4 of file testsub.f (unit = 10, file = 'fort.10')
Fortran runtime error: End of file
It looks like the logical unit was not given to the subroutine.I should add a compilation option somewhere... but I don't really know what and where...And to respond to the question "what happens if I compile both files with the same compiler ?" : the program runs perfectly :)
So if anyone as any idea...
This won't work. When you open the file in the main program, somewhere in the bowels of the ifort library the file will be opened and some state associated with it stored. GFortran knows nothing about the internal state of the ifort runtime library, and tries to look up the unit in its own runtime library state, which obviously fails.
这篇关于用2个编译器编译fortran程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!