Title: Bad value for Mingw32Compiler.compiler_cxx
Type: behavior Stage: test needed
Components: Distutils, Distutils2 Versions: Python 3.1, Python 3.2, Python 2.7, 3rd party
Status: open Resolution:
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: alydar, dobesv, eric.araujo, furrykef, rpetrov, tarek, woodsplitter
Priority: low Keywords: easy

Created on 2003-10-29 04:27 by alydar, last changed 2013-02-10 18:46 by rpetrov.

Messages (7)
msg18790 - (view) Author: Allen Chan (alydar) Date: 2003-10-29 04:27
Using the following three files:

-- begin files -----
/* hello.cpp */
#include <stdio.h>
void hello()
    printf("hello world\n");
/* hello.i */
%module hello
extern void hello();
import distutils
from distutils.core import setup, Extension

setup(name = "Hello World",
        version = "1.0",
        ext_modules = [Extension("_hello",
-- end files -------

executing the command:
 "python build_ext -cmingw32 --swig-cpp -f"
creates the following output:

-- begin output --
running build_ext
building '_hello' extension
swigging hello.i to hello_wrap.cpp
[ snipped ]
cc -mno-cygwin -shared -s build\temp.win32-2.3
\Release\hello_wrap.o build\temp.w
in32-2.3\Release\hello.o build\temp.win32-2.3
\Release\_hello.def -LC:\p\Python23
\libs -LC:\p\Python23\PCBuild -lpython23 -o 
error: command 'cc' failed: No such file or directory
-- end output --

It appears that defaults compiler_cxx 
to use "cc" and then uses it for the linking, and does not override the compiler_cxx 
entry.  If the self.set_executable() call in the __init__*( 
function of the Mingw32Compiler class also sets 
compiler_cxx to use "g++", then the extension build will 

msg18791 - (view) Author: David S. Rushby (woodsplitter) Date: 2004-02-11 23:18
Logged In: YES 

I also encountered this bug while trying to build a C++
extension with no SWIG involved.
msg18792 - (view) Author: Kef Li Eric MARCVS X (furrykef) Date: 2004-08-20 17:26
Logged In: YES 

ARGH! This bug is still in Python 2.3.4 and should have been
fixed A LONG TIME AGO! What am I supposed to do, have my
users fix their distutils by hand?

Sorry to be so gripy, but jeez. It tells you how to freaking
fix it...
msg18793 - (view) Author: Dobes V (dobesv) Date: 2007-05-22 17:18
Here's a workaround I used to fix the linker:

# Force g++ for linking
import distutils.sysconfig
old_customize_compiler = distutils.sysconfig.customize_compiler
def customize_compiler(compiler):
    if compiler.compiler_type == 'mingw':
       compiler.set_executables(linker_so='g++ -mno-cygwin -shared')
distutils.sysconfig.customize_compiler = customize_compiler

You could also override the compiler, too.
msg121420 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-18 02:18
The suggestion in the first message has to be turned into a patch.  A test has to be written too.
msg181837 - (view) Author: Roumen Petrov (rpetrov) * Date: 2013-02-10 18:45
In scope of issue12641 (Remove -mno-cygwin from distutils) I just publish a set of patches to modernize support for cygwin&mingw compilers.

My tests show that swig could be used successfully with patched mingw compiler. Test is based on patched official release 3.3.0 and my custom build of current master source with GNU windows compiler.
For protocol tested swig version is 2.0.9 and may be due syntax change swig module has to be described as :
/* hello.i */
%module hello
extern void hello(void);

extern void hello(void);

Distutils complain for --swig-cpp so command now is "python build_ext -cmingw32 --swig-cpp -f"
msg181838 - (view) Author: Roumen Petrov (rpetrov) * Date: 2013-02-10 18:46
Uhh "python build_ext -cmingw32 --swig-opts=-c++ -f"
Date User Action Args
2013-02-10 18:46:06rpetrovsetmessages: + msg181838
2013-02-10 18:45:24rpetrovsetnosy: + rpetrov
messages: + msg181837
2010-11-18 02:18:31eric.araujosetassignee: tarek -> eric.araujo

components: + Distutils2
title: C++ extensions using SWIG and MinGW -> Bad value for Mingw32Compiler.compiler_cxx
nosy: + eric.araujo
versions: + 3rd party
messages: + msg121420
2010-08-18 22:59:20BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-02-14 12:27:56tareksetassignee: tarek
2009-02-14 12:22:18ajaksu2setnosy: + tarek
type: behavior
stage: test needed
2008-01-20 19:36:36christian.heimessetpriority: normal -> low
keywords: + easy
versions: + Python 2.6, - Python 2.3
2003-10-29 04:27:08alydarcreate