Search code examples
pythonmingwdistutilsmingw-w64mingw32

Possible to change distutils default compiler options?


Win 10, x64, minGW64, Python 2.7, Anaconda

I am trying to compile zbar for use in Python 2.7 using python setup.py build --compiler=mingw32

Here's setup.py

from distutils.core import setup, Extension
from distutils.sysconfig import get_config_vars
setup(
    name = 'zbar',
    version = '0.10',
    author = 'Jeff Brown',
    author_email = '[email protected]',
    url = 'http://zbar.sourceforge.net',
    description = 'read barcodes from images or video',
    license = 'LGPL',
    long_description = open('README').read(),
    classifiers = [
        'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'Environment :: Console',
        'Environment :: X11 Applications',
        'Environment :: Win32 (MS Windows)',
        'Operating System :: POSIX',
        'Operating System :: Unix',
        'Operating System :: Microsoft :: Windows',
        'Topic :: Communications',
        'Topic :: Multimedia :: Graphics',
        'Topic :: Software Development :: Libraries',
    ],
    ext_modules = [
        Extension('zbar', [
                'zbarmodule.c',
                'enum.c',
                'exception.c',
                'symbol.c',
                'symbolset.c',
                'symboliter.c',
                'image.c',
                'processor.c',
                'imagescanner.c',
                'decoder.c',
                'scanner.c',
                ],
            libraries = [ 'zbar' ],
            library_dirs=["""C:\Program Files (x86)\ZBar\lib"""],
            include_dirs=[get_config_vars('INCLUDEDIR'),
                              get_config_vars('INCLUDEPY'),
                             """C:\Program Files (x86)\ZBar\include"""]
        ),
    ],
)

But I keep getting the following error...

running build
running build_ext
building 'zbar' extension
C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -I[None] -I['C:\\ProgramData\\Anaconda2\\include'] "-IC:\Program Files (x86)\ZBar\include" -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -c zbarmodule.c -o build\temp.win-amd64-2.7\Release\zbarmodule.o
gcc: error: unrecognized command line option '-mno-cygwin'; did you mean '-mno-clwb'?
error: command 'C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe' failed with exit status 1

From this post it appears that '-mno-cywin' is no longer a valid compilation option hence the error.

I found this post about distutils compiler options for Mac OS X 10.8.3 & get that somewhere distutils is reading some default flags from the oringal Python install but I'm none the wiser about how to change them.

How do I change the compiler options passed to distutils on a Windows 10 machine with an Anaconda distribution of Python ie with disutils.cfg missing?

Is it possible to write my own distutils.cfg?


Solution

  • The option is in distutils/cygwinccompiler.py. If you can edit the file in the Python installation ­just remove it.