Compiling PyGobject on windows

It has been a nightmare from the beginning….

Starting from the new release of Gobject bindings a lot has changed, we now have a new namespace glib where a lot of classes have been moved, of course retaining backward compatibility.

The new library (libpyglib) needs to be shared and not static, so I changed a couple of lines in Makefile.am to build it as a shared lib, basically adding -no-undefined in libpyglib_2_0_la_LDFLAGS, so far so good, the linker is much more happy.

The second problem came when python libs where not linked against this new library, after some resarch I came across a modification to the macro AM_CHECK_PYTHON_HEADERS into gnome-python-extras that Armin Burgmeier made, taking it from a modified version from Murray Cumming… it looks like we do a lot of copy/paste on this things.

So now I have got my $(PYTHON_LDFLAGS) to add to libpyglib_2_0_la_LIBADD and also to the other modules glib gio and gobject, so far so good.

Now i can get it to compile, the dll’s are created and I can change them to .pyd extension which python expects to have, so far so good.

Now when I try to import one of those modules from python I get:

>>> import glib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/python25/Lib/site-packages/gtk-2.0/glib\__init__.py", line 30, in <module>
    from glib._glib import *
ImportError: DLL load failed: The specified module could not be found.
>>>

Now I see two different problems here, obviously the first one is that libpyglib-2.0.dll  not found but it’s in the right place C:\opt\Python25\DLLs, the second problem is that there is a path hardcoded (/opt/python25/Lib/site-packages/gtk-2.0/glib\__init__.py) and I don’t understand why is that.

My .profile looks like this:

export PATH=/opt/gnome2/bin:/opt/svn/bin:/opt/python25:$PATH
export LD_LIBRARY_PATH=/opt/gnome2/lib
export PKG_CONFIG_PATH=/opt/gnome2/lib/pkgconfig:/c/opt/python25/lib/pkgconfig
export ACLOCAL_FLAGS="-I /opt/gnome2/share/aclocal"
export CC='gcc -mms-bitfields -mthreads'
export CPPFLAGS='-I/opt/gnome2/include -I/opt/gnuwin32/include -I/opt/python25/include'
export CFLAGS=-g
export LDFLAGS='-L/opt/gnome2/lib -L/opt/gnuwin32/lib'
export am_cv_python_pythondir=/opt/python25/Lib/site-packages
export am_cv_python_pyexecdir=/opt/python25/Lib/site-packages

I run autogen like this:

$ ./autogen.sh --prefix=/opt/Python25 --disable-docs

If someone has got ideas please help 🙂