我有一个 Fortran 模块,我正在尝试用 f2py 编译(如下所列)。当我删除模块声明并将子例程单独留在文件中时,一切正常。但是,如果模块声明如下所示,我会得到以下结果:
> f2py.py -c -m its --compiler=mingw itimes-s2.f
...
Reading fortran codes...
Reading file 'itimes-s2.f' (format:fix,strict)
crackline: groupcounter=1 groupname={0: '', 1: 'module', 2: 'interface', 3: 'subroutine'}
crackline: Mismatch of blocks encountered. Trying to fix it by assuming "end" statement.
...
c:\users\astay13\appdata\local\temp\tmpgh5ag8\Release\users\astay13\appdata\local\temp\tmpgh5ag8\src.win32-3.2\itsmodule.o:itsmodule.c:(.data+0xec): undefined reference to `itimes_'
collect2: ld returned 1 exit status
在 f2py 中编译模块或子程序有什么不同?我是否在模块中遗漏了导致 f2py 出现问题的重要内容?请注意,当我单独使用 gfortran 时,该模块编译得很好。
软件:Windows 7;gcc,gfortran 4.6.1(MinGW);蟒蛇3.2.2;f2py v2
次-s2.f:
module its
contains
subroutine itimes(infile,outfile)
implicit none
! Constants
integer, parameter :: dp = selected_real_kind(15)
! Subroutine Inputs
character(*), intent(in) :: infile
character(*), intent(in) :: outfile
! Internal variables
real(dp) :: num
integer :: inu
integer :: outu
integer :: ios
inu = 11
outu = 22
open(inu,file=infile,action='read')
open(outu,file=outfile,action='write',access='append')
do
read(inu,*,IOSTAT=ios) num
if (ios < 0) exit
write(outu,*) num**2
end do
end subroutine itimes
end module its