问题
I have written some code with python and f2py, mostly using linux. This all works fine, but now I would like to share this with windows users, so I am trying to make a module that is distributable to users who don't necessarily have gfortran or gcc. I've got access to a windows xp box, am using mingw with gfortran. I can compile and use the module on that machine, but on other machines the pyd created seems to require the dll's libgcc and libgfortran. Here is an example from http://www.scipy.org/F2PY_Windows:
subroutine hello ()
write(*,*)'Hello from Fortran90!!!'
end subroutine hello
Compile with
python c:\path\to\python\scripts\f2py.py -c \
--fcompiler=gnu95 --compiler=mingw32 \
-lmsvcr71 -m foo foo.f90
This works as expected on the machine I compiled it with, but if I copy it to another machine, I get
DLL load failed: The specified module could not be found.
Using dependency walker, I see it cannot find the dll's for libgcc_s_dw2-1.dll and libgfortran-3.dll. Is it possible to create a pyd that I can distribute without assuming the user has gcc and gfortran? I'm using python2.7 on both machines, both 32bit. One is xp, the other windows 7.
回答1:
As an alternative to including the libgcc
and libgfortran
dlls in the package, it should be possible to link against the static versions of these libraries, provided they are available in your build of MinGW. (At least, I assume it is. I have no experience with Python or pyds, but it is possible for regular executables and dlls.)
Look at the -static
option for linking, or if you need more control -static-libgcc
and -static-libgfortran
.
来源:https://stackoverflow.com/questions/9756212/creating-distributable-windows-python-module-with-f2py