portable extensions options for external libraries

Alexandre Guimond alexandre.guimond at siemens.com
Wed Oct 18 06:57:39 EDT 2006


Hi.

I want to create a portable setup.py file for windows / linux for an
extension package that i need to link with external libraries (gsl and
boost). on windows i do something like this:

imaging = Extension( 'pyag.imaging._imaging',
                     sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
                                 glob.glob(
'Source/pyag/imaging/Src/*.h' ) ),
                     include_dirs = ( get_numpy_include_dirs() +
                                      [ 'Source/pyag/imaging/Src/',
                                        'C:/Program
Files/boost/include/boost-1_35',
                                        'C:/Program
Files/GnuWin32/include'] ),
                     library_dirs = [ 'C:/Program Files/GnuWin32/lib'
],
                     libraries = [ 'libgsl', 'libgslcblas' ] )

obviously, the paths could vary. on unix, i need something like:

imaging = Extension( 'pyag.imaging._imaging',
                     sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
                                 glob.glob(
'Source/pyag/imaging/Src/*.h' ) ),
                     include_dirs = ( get_numpy_include_dirs() +
                                      [ 'Source/pyag/imaging/Src/' ] )
)

so my question is: what is the right way of specifying extensions
options (include_dirs, libraries, library_dirs) so that they are
portable between windows and linux? i'm thinking environment variables.
Though fairly easy to do, i was wondering if python/distutils provided
something more convenient, like searching through "common" directories,
though those aren't very standard on windows? Optimally, i would like
to have something like:

imaging = Extension( 'pyag.imaging._imaging',
                     sources = ( glob.glob(
'Source/pyag/imaging/Src/*.cpp' ) +
                                 glob.glob(
'Source/pyag/imaging/Src/*.h' ) ),
                     include_dirs = ( get_numpy_include_dirs() +
                                      [ 'Source/pyag/imaging/Src/' ] +
                                        boost_include_dirs +
                                        gsl_include_dirs ),
                     library_dirs = boost_library_dirs +
gsl_library_dirs,
                     libraries = boost_libraries + gsl_libraries )


thx for any help.

alex.




More information about the Python-list mailing list