Workarounds for C++ module linking issues - OK?
Hi,
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
properly.
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):
self.run_command('config')
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
build_ext.finalize_options(self)
def build_extension(self, ext):
# work around linker problem with MacPython 2.3
if sys.platform == 'darwin':
try:
self.compiler.linker_so.remove("-Wl,-x")
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':
try:
ext.libraries.append("stdc++")
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:
http://web.sabi.net/temp/setup.py
Thanks,
--
=Nicholas Riley
participants (1)
-
Nicholas Riley