[ python-Bugs-957198 ] C/C++ extensions w/ Python + Mingw (Windows)

SourceForge.net noreply at sourceforge.net
Fri Jun 4 12:02:53 EDT 2004


Bugs item #957198, was opened at 2004-05-20 05:36
Message generated for change (Comment added) made by theller
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=957198&group_id=5470

Category: None
>Group: Not a Bug
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Connelly (connelly)
>Assigned to: Thomas Heller (theller)
Summary: C/C++ extensions w/ Python + Mingw (Windows)

Initial Comment:

I am asking you to distribute libpython23.a with Python.

This is a library built by the Mingw compiler
(www.mingw.org).  When this file is present, it greatly
simplifies the process of installing a C/C++ extension.
 The below document explains how make this library, and
install a C/C++ extension with the Mingw compiler.

Currently, a library is provided for the proprietary
MSVC++ compiler (python23.lib), but not the open source
Mingw compiler.

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.
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


----------------------------------------------------------------------

>Comment By: Thomas Heller (theller)
Date: 2004-06-04 18:02

Message:
Logged In: YES 
user_id=11105

python23.lib (from MSVC) is provided with the Windows
installer because Python is built with that compiler.

I refuse to distribute libpython23.a for MingW with the
official installer mainly because I cannot test it, and I'm
not clear if there are issues with different mingw versions.

Wouldn't it be a better idea to provide a distutils patch
which will build libpython23.a with mingw itself, if the
library is not found?


----------------------------------------------------------------------

Comment By: Connelly (connelly)
Date: 2004-05-25 20:23

Message:
Logged In: YES 
user_id=1039782


I am using Mingw 3.1.0-1, released on Sep 15, 2003.  It is
the 'current' release of Mingw.  I'm using Python 2.3.3.

Issuing

  python setup.py install --compiler=mingw32 

causes an error.  I'm not sure which error -- I'll post it
here tomorrow when I'm at the right machine.

So I left off the --compiler option for the install step. 
This produced the error "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."

This error is not produced if VC++ is installed.  Thus you
need to find a machine WITHOUT VC++ to test out the build
process with Mingw32.

I don't know how to tell MinGW to use python23.lib.  Perhaps
this is all the result of not passing the right flag to
'python setup.py install'?  After all, it's using
msvccompiler.py, which seems suspicious.

I don't think I'm the only one having this problem.  See:

http://randomthoughts.vandorp.ca/WK/blog/758?t=item


----------------------------------------------------------------------

Comment By: Andrew I MacIntyre (aimacintyre)
Date: 2004-05-23 10:11

Message:
Logged In: YES 
user_id=250749

While older releases of MinGW certainly required this
library fiddling, such as the MingW 1.1 pkg with gcc 2.95, I
had been under the impression that recent versions could
quite happily use the MSVC python23.lib.  If you have tried
this and had it fail, which version of MinGW?

Using the --compiler=mingw32 build option should not require
patching Distutils, though you probably have to use it for
both build and install invocations.  You can just issue to
the install command (with the --compiler switch) which will
both build and install the extention.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=957198&group_id=5470



More information about the Python-bugs-list mailing list