我有一个由:
指定的Fortran共享库C FILE: OTHER.F
SUBROUTINE OTHER(FUN)
EXTERNAL FUN
INTEGER I
DO I=0,5
PRINT *, FUN(I)
ENDDO
END SUBROUTINE
C END OF FILE OTHER.F
我编译如下:gfortran -shared -O2 other.f -o libother.so -fPIC
我现在有另一个模块:
C FILE: CALLBACK.F
SUBROUTINE FOO(FUN,R)
EXTERNAL FUN
INTEGER I
REAL*8 R
R = 0D0
DO I=-5,5
PRINT *, FUN(I)
R = R + FUN(I)
ENDDO
CALL OTHER(FUN)
END SUBROUTINE
C END OF FILE CALLBACK.F
我希望使用f2py将此模块编译为python模块。为此,我输入了:
f2py -m callback -h callback.pyf callback.f
接下来是:
f2py -c callback.pyf callback.f -L. -lother
然后我使用Python解释器运行:
import callback
callback.foo(lambda x: 1)
预期的行为是:
foo
)other
内foo
来电的b / c)观察到的行为是:
ImportError: libother.so: cannot open shared object file: No such file or directory
如果我nm callfun.so
,我可以看到other
未定义