python - f2py 错误 : undefined symbol

标签 python fortran f2py

我需要用 f2py 包装一个简单的 fortran90 代码。 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

然后我把它包起来

f2py  -m test -c test.f90

但是当我在 python 中导入它时

In [2]: import test

它提示我说错误

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

关于如何修复它的任何想法?谢谢。

最佳答案

在 gasdev 函数中,您将 ran2 声明为外部函数。当您不链接任何此类函数时,导入模块将失败。

相反,在 gasdev 中删除 ran2 的声明,在这种情况下,ran2 调用使用模块中 ran2 函数的显式接口(interface),并且一切正常。

关于python - f2py 错误 : undefined symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7803799/

相关文章:

python - Pandas 中的多键横截面。处理未命中和重复索引

python - 将复杂数据读入 numpy 数组

algorithm - 将 VBA 代码转换为 Fortran

c - 使用 f2c 从 Fortran 翻译而来的 C 代码中出现错误

python-3.x - python-fortran集成: callback comparison between f2py and ctypes

python - 如何在 Python 中执行代码字符串?

python - 与 numpy 的 np.random.RandomState 和 Python 的 random.Random 相互转换?

fortran - 使用常量参数调用函数时出现段错误

python - scipy.weave 对于更复杂的性能代码的限制

python - f2py 中的 malloc 错误