[Distutils] distutils - locating include files, specifying C libraries

Joe Van Andel vanandel@ucar.edu
Tue, 07 Mar 2000 09:31:08 -0700


This is a multi-part message in MIME format.
--------------1E265613DB92B696329ED604
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'm trying to use distutils (CVS from 3/6/2000) to build C++ extensions
that use the Numeric library.  I'm using Python 1.5.2, Redhat 6.1,
Solaris 2.6 and Gcc 2.95.2

I'm pleased that I can build and install my  extensions for both Solaris
and Linux, now that I've built workarounds for the two problems I
describe below.  Given that distutils automatically builds libraries and
objects in machine-dependent temporary directories, I find it much
easier to use than the corresponding Makefiles.


Here are two problems that should be addressed.

Problem 1 - locating Python extension include files.

Numeric has its own include files, which are installed under
/usr[/local]/include/python1.5/Numeric

I want to specify the location of the Numeric include files in an
installation/machine independent way.  I added the following into my
setup.py file:

######################

from distutils import sysconfig

#determine location of Python include files, to locate Numeric includes

config_h = sysconfig.get_config_h_filename()
py_inc = os.path.dirname(config_h)
NUM_INC = os.path.join(py_inc, 'Numeric')

#################################
I've attached a patch for sysconfig.py that defines get_python_inc(), to
provide a cleaner way to
find where the python includes are located.

This allows a user to find the python include files as follows:
py_inc = sysconfig.get_python_inc()
NUM_INC = os.path.join(py_inc, 'Numeric')

Problem 2 - specifying architecture/compiler specific libraries to
setup.py

When I link my extension on Linux (RH 6.1), I need to specify
 'libraries': ['gcc', 'stdc++','pthread'],

However, when I link my extensions on Solaris 2.6, these libraries do
not exist.

(At this point, we start approaching the complex world of GNU
'autoconf', that dynamically checks for the existence of specified
libraries! )

Here's a solution, is there a better one?

from distutils.util import get_platform
plat = get_platform()

# machine dependent C/C++ support libs
if plat == 'linux-i586' :
    CLIBS=['gcc', 'stdc++','pthread']
else:
    CLIBS=[]


.
.
.
 ext_modules = [
                      ('Perp.a1pp.pulsepairc',
                       {'sources': ['a1pp/pulsepair.cc',
                                    'a1pp/pulsepair_wrap.cc'],
                        'libraries': CLIBS,
                        },
                        ),




-- 
Joe VanAndel  	          
National Center for Atmospheric Research
http://www.atd.ucar.edu/~vanandel/
Internet: vanandel@ucar.edu
--------------1E265613DB92B696329ED604
Content-Type: text/plain; charset=us-ascii;
 name="sysconfig.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sysconfig.patch"

*** sysconfig.py.orig	Tue Mar  7 08:44:18 2000
--- sysconfig.py	Tue Mar  7 08:45:18 2000
***************
*** 25,30 ****
--- 25,37 ----
          return os.path.join(exec_prefix,
                              "include", "python" + sys.version[:3],
                              "config.h")
+ def get_python_inc():
+     """Return full pathname of installed config.h file."""
+     if os.name == "nt":
+         return os.path.join(exec_prefix, "include")
+     else:
+         return os.path.join(exec_prefix,
+                             "include", "python" + sys.version[:3])
  
  def get_makefile_filename():
      """Return full pathname of installed Makefile from the Python build."""

--------------1E265613DB92B696329ED604--