How to Build Python 2.3.3 C/C++ Extensions in Windows Using Mingw32

Discussion in 'Python' started by C. Barnes, May 20, 2004.

  1. C. Barnes

    C. Barnes Guest

    Normally, one uses the following procedure to build
    and install a C/C++
    extension:

    python setup.py build --compiler=your_compiler
    python setup.py install

    For Python 2.3.3 on Windows, with the Mingw
    (Minimalist GNU) compiler,
    the following steps must be taken:

    1. Find your Mingw bin directory. Copy gcc.exe to
    cc.exe.

    2. Get PExports from either of:

    http://sebsauvage.net/python/pexports-0.42h.zip

    http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip

    Extract pexports.exe to your Mingw bin directory.

    3. Find pythonxx.dll. It should be in your main
    Python directory. Do
    the following:

    pexports python23.dll > python23.def
    dlltool --dllname python23.dll --def python23.def
    --output-lib libpython23.a

    4. Copy libpythonxx.a to \python\libs.

    5. Patch distutils. Locate
    \python\lib\distutils\msvccompiler.py, open
    it, and find the following lines (around line 211):

    if len (self.__paths) == 0:
    raise DistutilsPlatformError, \
    ("Python was built with version %s
    of Visual Studio, "
    "and extensions need to be built
    with the same "
    "version of the compiler, but it
    isn't installed." % self.__version)

    Delete these.

    6. Move back to the directory of your extension. Do
    the following:

    python setup.py build --compiler=mingw32
    python setup.py install


    Ideally, only step 6 should be required to install an
    extension.

    I submitted the patch for step 5 to
    python.sourceforge.net.
    Steps 2-4 can be avoided if the libpythonxx.a file is
    distributed
    with Python. I'll email the Python folks and ask
    them to do this.
    Step 1 can probably be avoided with another patch.

    This document is based on
    http://sebsauvage.net/python/mingw.html,
    which was written for Mingw + Python 2.2.

    Thanks,
    Connelly Barnes

    PS:
    To test this process, try compiling myspell-python, a
    spell checking library for Python. See
    http://oregonstate.edu/~barnesc/myspell-python-1.01.tar.gz





    __________________________________
    Do you Yahoo!?
    Yahoo! Domains – Claim yours for only $14.70/year
    http://smallbusiness.promotions.yahoo.com/offer
    C. Barnes, May 20, 2004
    #1
    1. Advertising

  2. On 2004-05-20, C. Barnes wrote in <>:
    >
    > 2. Get PExports from either of:


    This is awfully outdated.

    >
    > http://sebsauvage.net/python/pexports-0.42h.zip
    >
    > http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip
    >
    > Extract pexports.exe to your Mingw bin directory.


    Rather go to http://mingw.org/ and download the mingw-utils package.
    Hopefully that's the same place you obtained your compiler, linker and
    libraries.

    A better writer wants to submit a patch for the distutils manual?

    --
    Alejandro López-Valencia
    qenqhy ng rgo qbg arg qbg pb http://dradul.tripod.com/
    \u864e\u306e\u795e\u6bbf
    Alejandro =?iso-8859-1?Q?L=F3pez-Valencia?=, May 20, 2004
    #2
    1. Advertising

  3. C. Barnes

    Roger Binns Guest

    C. Barnes wrote:
    > 5. Patch distutils. Locate
    > \python\lib\distutils\msvccompiler.py, open
    > it, and find the following lines (around line 211):
    >
    > if len (self.__paths) == 0:
    > raise DistutilsPlatformError, \
    > ("Python was built with version %s
    > of Visual Studio, "
    > "and extensions need to be built
    > with the same "
    > "version of the compiler, but it
    > isn't installed." % self.__version)
    >
    > Delete these.


    You don't need that. Do this instead:

    python setup.py build --compiler=mingw32 bdist_wininst

    Roger
    Roger Binns, May 20, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. orion30

    MSYS / MINGW32 / PYTHON / SWIG

    orion30, Jun 24, 2003, in forum: Python
    Replies:
    1
    Views:
    2,316
  2. Chris Gonnerman
    Replies:
    7
    Views:
    420
    John Machin
    Aug 9, 2003
  3. Dave Haynes
    Replies:
    2
    Views:
    364
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Aug 28, 2003
  4. J. D.
    Replies:
    12
    Views:
    158
    Roger Pack
    Jun 1, 2009
  5. Marco Mastrodonato

    I can't use DBI with ruby mingw32 on windows

    Marco Mastrodonato, Aug 25, 2009, in forum: Ruby
    Replies:
    0
    Views:
    172
    Marco Mastrodonato
    Aug 25, 2009
Loading...

Share This Page