Subsections

- 3.1 Using non-Microsoft compilers on Windows
  - 3.1.1 Borland C++
  - 3.1.2 GNU C / Cygwin / MinGW32

#
3 Building Extensions: Tips and Tricks

(This is the section to read for people doing any sort of interesting build. Things to talk about:

- the Setup file (any platform now, but Unix-biased)
- CFLAGS and LDFLAGS (must implement them first!)
- using non-MS compilers on Windows (how to convert Python's library, ...)

##
3.1 Using non-Microsoft compilers on Windows

### 3.1.1 Borland C++

This subsection describes the necessary steps to use Distutils with the Borland C++ compiler version 5.5.1

First you have to know that the Borland's object file format(OMF) is different from what is used by the Python version you can download from the Python web site. (Python is built with Microsoft Visual C++, which uses COFF as object file format.) For this reason you have to convert Python's library python20.lib into the Borland format. You can do this as follows:

      coff2omf python20.lib python20_bcpp.lib

The coff2omf program comes with the Borland compiler. The file python20.lib is in the Libs directory of your Python installation. If your extension uses other libraries (zlib,...) you have to convert them too.

The converted files have to reside in the same directories as the normal libraries.

How does Distutils manage to use these libraries with their changed names? If the extension needs a library (eg. foo) Distutils checks first if it finds a library with suffix _bcpp (eg. foo_bcpp.lib) and then uses this library. In the case it doesn't find such a special library it uses the default name (foo.lib.)2

To let Distutils compile your extension with Borland C++ you now have to type:

      python setup.py build --compiler=bcpp

If you want to use the Borland C++ compiler as default, you should consider to write it in your personal or system-wide configuration file for Distutils (see section 6.)

** One place to look: http://www.cyberus.ca/~g_will/pyExtenDL.shtml **

### 3.1.2 GNU C / Cygwin / MinGW32

This section describes the necessary steps to use Distutils with the GNU C/C++ compilers in their Cygwin and MinGW32 distributions.3

** For a Python which was built with Cygwin, all should work without any of these following steps. **

For these compilers we have to create some special libraries too. This task is more complex as for Borland's C++, because there is no program to convert the library (inclusive the references on data structures.)

First you have to create a list of symbols which the Python DLL exports. (You can find a good program for this task at http://starship.python.net/crew/kernr/mingw32/Notes.html, see at PExports 0.42h there.)

      pexports python20.dll >python20.def

Then you can create from these information an import library for gcc.

      dlltool --dllname python20.dll --def python20.def --output-lib libpython20.a

The resulting library has to be placed in the same directory as python20.lib. (Should be the libs directory under your Python installation directory.)

If your extension uses other libraries (zlib,...) you might have to convert them too. The converted files have to reside in the same directories as the normal libraries do.

To let Distutils compile your extension with Cygwin you now have to type

      python setup.py build --compiler=cygwin

and for Cygwin in no-cygwin mode4 or for MinGW32 type

      python setup.py build --compiler=mingw32

If you want to use any of these options/compilers as default, you should consider to write it in your personal or system-wide configuration file for Distutils (see section 6.)

** One place to look: http://www.zope.org/Members/als/tips/win32_mingw_modules **

** For converted import libraries for python20, tcl83 and tk83 in cygwin/mingw32 and bcpp format, see http://www.htw-dresden.de/~liebschr/PyOpenGL/py2.0-libs.tgzand for the missing header files of the in python2.0 included tcl/tk, see http://www.htw-dresden.de/%7Eliebschr/PyOpenGL/py2.0-tk8.3-header.tgz. **

#### Footnotes

... 5.5.1
  Check http://www.borland.com/bcppbuilder/freecompiler/ for download
...foo.lib.)2
  This also means you could replace all existing COFF-libraries with OMF-libraries of the same name.
... distributions.3
  Check http://sources.redhat.com/cygwin/ and http://www.mingw.org for more information
... mode 4
  Then you have no POSIX emulation available, but you also don't need cygwin1.dll.