Python wrapper for the Fast Light Toolkit pyFLTK


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:

  1. Get and install MinGW gcc
  2. Create libpython24.a
  3. Set environment variable FLTK_HOME
  4. Compile/install the extension with distutils

1. Get and install MinGW gcc

You 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 .a file (libpython24.a to be precise.). To convert python24.lib to libpython24.a proceed as follows:

  1. Download pexports (from
  2. Get Python24.dll (it should be somewhere on your harddrive).
  3. Run : pexports python24.dll > python24.def
    This will extract all symbols from python24.dll and write them into python24.def.
  4. 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).
  5. 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 variables

If 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 pyFLTK

In the pyFLTK distribution directory, change to the folder python, then run the following:

python 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.pyd and Those are our compiled extension and the created Python wrapper.

Copy them to $(PYTHON_HOME)\libs\site-packages, where $(PYTHON_HOME) refers to the directory where Python is installed. Alternatively, you can run the command:

python build --compiler=mingw32 install

You should now be able to run the demo programs in the directory test.

If there are any problems using this procedure please direct your questions to the pyfltk-user mailing list. Logo