distutils compiler flags for extension modules

Floris Bruynooghe floris.bruynooghe at gmail.com
Fri Mar 20 16:27:15 CET 2009

On Mar 20, 9:48 am, Christian Meesters <meest... at gmx.de> wrote:
> as I got no answers with the previous question (subject: disabling
> compiler flags in distutils), I thought I should ask the question in a
> different way: Is there an option to set the compiler flags for a C/C++
> extension in distutils? There is the extra_compile_args-option in the
> Extension class, yet this offers only to give additional flags, but I'd
> like to have 'total' control about the compile args. Any hint?

You can subclass the build_ext class and overwrite .finalize_options()
to do something like:

    for ext in self.extensions:
        # fiddle with ext.extra_compile_args

And if that isn't enough you can modify the compiler (with some flags)
by overwriting .build_extension() and modify self.compiler using
it's .set_executables() method (file:///usr/share/doc/python2.5/html/
dist/module-distutils.ccompiler.html#l2h-37) before calling


More information about the Python-list mailing list