未定义的参考`

我正在尝试使用f2py编译一个Fortran 90文件,以便在Python模块中使用。 该文件由两个子例程组成。 我可以在命令窗口中使用gfortran ljlib3.f90来编译文件,但是在尝试使用f2py编译子例程时出现错误。

我在Win 10(Python 2.7.10)和Mingw-w64(全部正确安装)上使用Python(x,y)。 这很困难,因为这是来自教程的其他人的代码,在我的情况下,直到编译结束(与教程比较时)结束时,所有代码都可以正常工作。

这里是文件ljlib3.f90中的子例程:

subroutine EnergyForces(Pos, L, rc, PEnergy, Forces, Dim, NAtom)
implicit none
integer, intent(in) :: Dim, NAtom
real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos
real(8), intent(in) :: L, rc
real(8), intent(out) :: PEnergy
real(8), intent(inout), dimension(0:NAtom-1, 0:Dim-1) :: Forces
!f2py intent(in,out) :: Forces
real(8), dimension(Dim) :: rij, Fij, Posi
real(8) :: d2, id2, id6, id12
real(8) :: rc2, Shift
integer :: i, j
PEnergy = 0.
Forces = 0.
Shift = -4. * (rc**(-12) - rc**(-6))
rc2 = rc * rc
do i = 0, NAtom - 1
    !store Pos(i,:) in a temporary array for faster access in j loop
    Posi = Pos(i,:)
    do j = i + 1, NAtom - 1
        rij = Pos(j,:) - Posi
        rij = rij - L * dnint(rij / L)
        !compute only the squared distance and compare to squared cut
        d2 = sum(rij * rij)
        if (d2 > rc2) then
            cycle
        end if
        id2 = 1. / d2            !inverse squared distance
        id6 = id2 * id2 * id2    !inverse sixth distance
        id12 = id6 * id6         !inverse twelvth distance
        PEnergy = PEnergy + 4. * (id12 - id6) + Shift
        Fij = rij * ((-48. * id12 + 24. * id6) * id2)
        Forces(i,:) = Forces(i,:) + Fij
        Forces(j,:) = Forces(j,:) - Fij
    enddo
enddo
end subroutine

subroutine VVIntegrate(Pos, Vel, Accel, L, CutSq, dt, KEnergy, PEnergy, Dim, 
NAtom)
implicit none
integer, intent(in) :: Dim, NAtom
real(8), intent(in) :: L, CutSq, dt
real(8), intent(inout), dimension(0:NAtom-1, 0:Dim-1) :: Pos, Vel, Accel
!f2py intent(in,out) :: Pos, Vel, Accel
real(8), intent(out) :: KEnergy, PEnergy
external :: EnergyForces
Pos = Pos + dt * Vel + 0.5 * dt*dt * Accel
Vel = Vel + 0.5 * dt * Accel
call EnergyForces(Pos, L, CutSq, PEnergy, Accel, Dim, NAtom)
Vel = Vel + 0.5 * dt * Accel
KEnergy = 0.5 * sum(Vel*Vel)
end subroutine

注意!f2py intent(in,out)...指令也用于子例程。

在使用f2py命令之后:

f2py -c -m ljlib ljlib3.f90 --fcompiler=gnu95 compiler=mingw32

出现以下错误:

C:Program_Filesmingw-w64x86_64-7.2.0-posix-sjlj-rt_v5-
rev1mingw64bingfortran.exe -Wall -g -Wall -g -shared 
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-2.7ljlibmodule.o 
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-2.7fortranobject.o 
c:userspc2012appdatalocaltemptmp_pzjlcReleaseljlib3.o -
LC:Program_Filesmingw-w64x86_64-7.2.0-posix-sjlj-rt_v5-
rev1mingw64libgccx86_64-w64-mingw327.2.0 -LC:Python27libs -
LC:Python27PCbuild -lpython27 -lgfortran -o .ljlib.pyd
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-
2.7ljlibmodule.o:ljlibmodule.c:(.text+0x1a): undefined reference to 
`__imp_PyFloat_Type'
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-
2.7ljlibmodule.o:ljlibmodule.c:(.text+0x26): undefined reference to 
`__imp_PyType_IsSubtype'
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-
2.7ljlibmodule.o:ljlibmodule.c:(.text+0x55): undefined reference to 
`__imp_PyNumber_Float'  ...

error: Command "C:Program_Filesmingw-w64x86_64-7.2.0-posix-sjlj-rt_v5-
rev1mingw64bingfortran.exe -Wall -g -Wall -g -shared 
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-2.7ljlibmodule.o 
c:userspc2012appdatalocaltemptmp_pzjlcReleaseusers 
pc2012appdatalocaltemptmp_pzjlcsrc.win32-2.7fortranobject.o 
c:userspc2012appdatalocaltemptmp_pzjlcReleaseljlib3.o -
LC:Program_Filesmingw-w64x86_64-7.2.0-posix-sjlj-rt_v5-
rev1mingw64libgccx86_64-w64-mingw327.2.0 -LC:Python27libs -
LC:Python27PCbuild -lpython27 -lgfortran -o .ljlib.pyd" failed with exit 
status 1

许多undefined reference to ....“`后出现错误。 我想这是一个PATH问题,但我不确定。

链接地址: http://www.djcxy.com/p/96145.html

上一篇: undefined reference to `

下一篇: f2py is not able to link with NetCDF library