简体   繁体   English

f2py错误:未定义符号

[英]f2py error: undefined symbol

I need to wrap a simply fortran90 code with f2py. 我需要用f2py包装一个简单的fortran90代码。 The fortran module "test.f90" is fortran模块“ test.f90”是

module util

contains

FUNCTION gasdev(idum)
implicit none
INTEGER(kind=4), intent(inout) :: idum
REAL(kind=8) :: gasdev, ran2
print*,idum
gasdev = ran2(idum)
return
END FUNCTION

FUNCTION ran2(idum)
implicit none
INTEGER(kind=4), intent(inout) :: idum
REAL(kind=8) :: ran2
print*,idum
ran2=2.D0
return
END FUNCTION
end module util

and then I wrap it with 然后用

f2py  -m test -c test.f90

but when I import it in python 但是当我在python中导入它时

In [2]: import test

it prompted me with error saying 它提示我错误

ImportError: ./test.so: undefined symbol: ran2_

Any ideas on how to fix it? 关于如何解决它的任何想法? Thanks. 谢谢。

In function gasdev you declare ran2 as an external function. 在函数gasdev中,您将ran2声明为外部函数。 As you then don't link in any such function importing the module will fail. 由于您随后未链接任何此类函数,因此模块导入将失败。

Instead, remove the declaration of ran2 in gasdev, in which case the ran2 call uses the explicit interface to the ran2 function in the module, and everything works. 而是在gasdev中删除ran2的声明,在这种情况下,ran2调用使用模块中ran2函数的显式接口,并且一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM