[Distutils] Workarounds for C++ module linking issues - OK?

Nicholas Riley njriley at uiuc.edu
Thu Sep 25 18:00:54 EDT 2003


It's me again.  With the exception of the clean problem in my previous
email, I think I've got my distutils-based setup script working

To do so, I've needed to add a few workarounds where distutils wasn't
doing the right thing, and I couldn't convince it to do so by ordinary
means.  The changes revolve around the fact that the module is written
in C++, and I want to provide support back to Python 1.5.2.

They are as follows.

class build_mkext(build_ext):
    # force use of C++ compiler (helps on some platforms)
    def finalize_options(self):

        import os
        cc = os.environ.get('CXX', sysconfig.get_config_var('CXX'))
        if not cc:
            cc = sysconfig.get_config_var('CCC') # Python 1.5.2
        if cc:
            os.environ['CC'] = cc

    def build_extension(self, ext):
        # work around linker problem with MacPython 2.3
        if sys.platform == 'darwin':
            except: pass
        # work around linker problem with Linux, Python 2.2 and earlier:
        # despite setting $CC above, still uses Python compiler
        if sys.platform == 'linux2':
            except: pass

Does this all look OK?  I realize it's not the cleanest thing in the
world, but such workarounds seldom are.  I just don't want to do
something that will break in the near future, and this is the first
distutils setup script I've written. :-)

If you need to see the rest of the file, it's at:



=Nicholas Riley <njriley at uiuc.edu> | <http://www.uiuc.edu/ph/www/njriley>

More information about the Distutils-SIG mailing list