私はf2py(下記)にコンパイルしようとしているFortranモジュールを持っています。モジュール宣言を削除して、サブルーチンをそのままファイルに残すと、すべて正常に動作します。モジュールは、以下のように宣言されている場合は、私は次のような結果を得る: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
ファイル名の末尾に.f90を付けるように名前を変更してください。コンパイラは、それが固定フォーマットファイル(少なくとも私のマシン上)であると仮定しているようです。私は 'f2py -c -m itsm itimes-s2.f90'を使用しています。私は2つの異なるLinuxコンピュータでそれをテストしました。 –
おかげでウラジミール! '.f90'拡張子に名前を変更すると、PythonモジュールとFortranモジュールが同じ名前を持っていてもうまく機能しました。 – astay13