Installing pyFLTK using the MinGW compiler
Under Windows, if you do not have Microsoft Visual C++ installed, you can still build pyFLTK using the MinGW environment. There are several steps necessary to compile andd link the extension successfully, they will be described here:
- Get and install MinGW gcc
- Create libpython24.a
- Set environment variable FLTK_HOME
- Compile/install the extension with distutils
1. Get and install MinGW gccYou can either install the complete Cygwin environment or only the MinGW compiler. In any case, what we need is gcc the Gnu C/C++ compiler. Please refer to the MinGW or Cygwin documentation for learning how to install and run gcc.
If installed properly, you should be able to run
gcc --version anywhere.
1. Configure gcc
Unfortunately, Python is linked against msvcr71, whereas MinGW links against msvcrt. This will cause a number of memory problems, often crashing the application upon termination. If you can live with this, alas! If not, you have to force MinGW to link against msvcr71. This can be done as follows:
a) Locate the file "specs", this should be in directory MinGW\lib\gcc\mingw32\3.4.2
b) Change all occurences of -lmsvcrt to -lmsvcr71
2. Create libpython24.a
To create Python extensions, you need to link against the Python library. Unfortunately, most Python distributions
are provided with Python24.lib, a library in Microsoft Visual C++ format. GCC expects a
libpython24.a to be precise.). To convert
- Download pexports (from http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip).
Python24.dll(it should be somewhere on your harddrive).
- Run :
pexports python24.dll > python24.def
This will extract all symbols from python24.dll and write them into python24.def.
- Run :
dlltool --dllname python24.dll --input-def python24.def --output-lib libpython24.a
This will create libpython24.a (dlltool is part of the MinGW utilities).
- Copy libpython24.a to
$(PYTHON_HOME)\libs\(in the same directory as python24.lib).
This should work for all Python versions, indeed it should work for converting any Windows DLL.
3. Set environment variablesIf FLTk was installed in the proper places, usually with
make install, then you can skip this step. Otherwise the environment variable FLTK_HOME has to be set to the root directory of the FLTK distribution.
4. Compile pyFLTKIn the pyFLTK distribution directory, change to the folder python, then run the following:
python setup.py build --compiler=mingw32
This will compile and link the pyFLTK extension.
You may get a few compiler warnings about "declared but unused" symbols, they can be safely ignored.
Look into the
\build\lib.win32-2.2 subdirectory: you should see
fltk.py. Those are our compiled extension and the created Python wrapper.
$(PYTHON_HOME)refers to the directory where Python is installed. Alternatively, you can run the command:
You should now be able to run the demo programs in the directory
python setup.py build --compiler=mingw32 install
If there are any problems using this procedure please direct your questions to the pyfltk-user mailing list.