I wanted to use mod_wsgi with Python 2.5 and Apache 2.2 on Windows.
There
don't seem to be any binaries available for this (I did find one
eventually,
but that was of mod_wsgi version 2.3 and I had to get it from the
Wayback site).
Python 2.5 was built with Microsoft Visual C 2003, which means that it
links
against MSVCR71.DLL, and mod_wsgi must do the same. Normally this
would mean
building using MS VC 2003, but that's not available any more, so I had
to use
MinGW.
It turned out to be tricky to make this work, so I'm posting the
details here
in case they help someone else. I don't expect a lot of interest in
linking
against Python 2.5, but I know there isn't much information out there
on how
to compile modules for Windows using MinGW instead of specific MSVCs,
so this
might be more generally useful.
To start, get the tool environment set up:
- Install Apache 2.2 and Python 2.5, with header files.
- Install MinGW, including MSYS and developer tools. Also download and
install
the 'pexports' package from the MinGW Sourceforge site; it doesn't
get
included by the default MinGW installation.
- Possibly install the Visual C 2003 runtime (MSVCR71.DLL). This was
on my
system already; I don't really know what put it there. Might even
have been
the Python installation.
- Download the mod_wsgi source and unpack it into a working folder.
- Copy the files 'libapr-1.dll', 'libaprutil-1.dll' and 'libhttpd.dll'
from
the Apache 'bin' folder to the working folder. This isn't really
needed; it
just saves time repeatedly specifying the Apache 'bin' folder.
- Create import libraries for the Apache DLLs 'apr-1', 'aprutil-1' and
'httpd'. The recipe for this is:
- run "pexports libapr-1.dll | sed -e 's/^_//' > tmp"
- then "dlltool -l apr-1.lib -d tmp --add-stdcall-underscore
libapr-1.dll"
- and do these two steps for 'aprutil-1' and 'httpd' too.
- MinGW by default links against MSVCRT.DLL, which I believe is the
run-time
library from Visual C 6. To change this:
- run 'gcc -dumpspecs > specs' to create a specs file,
- edit 'specs' and find the line containing '-lmsvcrt'. In that
line, change
'-lmoldname' to '-lmoldname71' and change '-lmsvcrt' to '-
lmsvcr71',
- move 'specs' to where it will be picked up by GCC. With a default
installation of MinGW 4.5.2, that means copying it to
/c/MinGW/lib/gcc/mingw32/4.5.2/specs
You might want to compile a "hello world" at this point and confirm
it is
linked against MSVCR71.DLL. I used Dependency Walker from
http://www.dependencywalker.com to do this.
There were a couple of fixes needed for MS-VC and MinGW compatibility
issues:
- For some reason, gcc tries to compile the function
'apr_dynamic_fn_retrieve'
with __cdecl calling conventions, even though it should be
__stdcall. I
worked around this by editing the Apache include file
'apr_optional.h' and
putting '__attribute__((__stdcall__))' at the start of the line
declaring
'apr_dynamic_fn_retrieve'.
I have no idea why this happens, because the existing macros clearly
expand
to include a '__stdcall__' directive. It might even be a bug in gcc;
if
anyone has an explanation I'd like to hear it.
- MSVC and gcc pack C structures containing bitfields differently. So
far, I
have only found one place where this causes problems. I had to edit
'apr_uri.h' and declare an extra component at the end of the 'struct
api_uri_t' structure: 'int mingw_padding;'. You can see the bitfield
declarations that cause the trouble just above where this dummy
field needs
to go.
I haven't tested this fix yet. It might be that this isn't enough to
make
the bitfields themselves work properly. It is enough to get basic
WSGI
functions up and running though.
Having done all that, the command
gcc -o mod_wsgi.so mod_wsgi.c -Wl,--enable-stdcall-fixup
-I /c/Program\ Files/Apache\ Software\ Foundation/Apache2.2/
include
-I /c/Python25/include -L . -L /c/WINDOWS/system32 -lapr-1 -
laprutil-1
-lhttpd -lpython25 -shared
is enough to create an apparently-working mod_wsgi.so module. By
"apparently"
I mean that I have used 'WSGIScriptAlias' to run a simple Python
script that
returns HTML that is then displayed in the browser.
Regards,
--
Jon Ashley
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.