我试图使用命令f2py:
C:\Python27\python.exe setup.py build_ext --inplace --fcompiler=g95
我的Fortran文件是:
module test_f90
implicit none
real *8 :: delta
contains
subroutine test_f(val, r)
real*8, intent(out) :: val
real*8, intent(in) :: r
val = 0.5*( 1 + erf(r/delta) )
end subroutine
end module test_f90
但我有这个错误:
test_fmod.o : error LNK2019: unresolved external symbol __g95_erf_r8 rÚfÚrencÚ d
ans la fonction _test_f90_MP_test_f
_test_f90.pyd : fatal error LNK1120: 1 externes non rÚsolus
error: Command "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.e
xe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\P
Cbuild /LIBPATH:C:\Python27\PC\VS9.0 /LIBPATH:C:\Python27\libs /LIBPATH:C:\Pytho
n27\PCbuild /LIBPATH:C:\Python27\PC\VS9.0 /EXPORT:init_test_f90 build\temp.win32
-2.7\Release\build\src.win32-2.7\_test_f90module.obj build\temp.win32-2.7\Releas
e\build\src.win32-2.7\fortranobject.obj build\temp.win32-2.7\Release\test_fmod.o
build\temp.win32-2.7\Release\build\src.win32-2.7\_test_f90-f2pywrappers2.o /OUT
:_test_f90.pyd /IMPLIB:build\temp.win32-2.7\Release\build\src.win32-2.7\_test_f9
0.lib /MANIFESTFILE:build\temp.win32-2.7\Release\build\src.win32-2.7\_test_f90.p
yd.manifest" failed with exit status 1120
如果我用val = 0.5*( 1 + erf(r/delta) )
替换线val = 0.5*( 1 + sin(r/delta) )
f2py效果很好。所以问题是由于erf
功能,但我不知道为什么。我认为sin
和erf
是同一种功能?
如OP所报告的那样,使用gcc 4.1.2和g95 0.93来实现这一目标。