我有一个Fortran模块,我试图用f2py编译(下面列出)。当我删除模块声明并将它自己的子例程留在文件中时,一切正常。但是,如果模块声明如下,我得到以下结果:使用f2py编译fortran模块
> 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); python 3.2.2; f2py V2
itimes-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
我试着运行'f2py -c --compiler = mingw32 -m itsm itimes-s2.f',但是错误信息仍然是一样的。 – astay13 2011-12-20 15:19:20
尝试重命名文件以使其具有.f90后缀。似乎编译器认为它是一个固定格式的文件(至少在我的机器上)。我正在使用'f2py -c -m itsm itimes-s2.f90',它可以工作。我在2台不同的linux电脑上测试过它。 – 2011-12-20 20:54:28
谢谢弗拉基米尔!一旦我将其重命名为'.f90'扩展名,即使Python和Fortran模块具有相同的名称,它也可以很好地工作。 – astay13 2011-12-20 21:50:57