473,503 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

portable extensions options for external libraries

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.

Oct 18 '06 #1
1 1364
Alexandre Guimond wrote:
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.
The user can already use command-line options and CFLAGS if he so desires, so I
wouldn't add any new environment variables.

$ CFLAGS=-I/opt/local/include python setup.py build_ext -L/opt/local/lib
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?
distutils wouldn't do any searching at all. Your compiler will, though.
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 )
That's pretty much how everyone else does it. Just make sure that
boost_{include,library}_dirs and gsl_{include,library}_dirs are defined near the
top of the file with suitable comments to draw attention to them.

However, I might suggest making a setup.cfg with something like the following
section (unindented):

# Uncomment and modify the following section to configure the locations of the
# Boost and GSL headers and libraries.

#[build_ext]
#include-dirs=/opt/local/include,/usr/local/include
#library-dirs=/opt/local/lib,/usr/local/lib

Changing data in a data file feels better to me than changing data in a program
for some reason.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2610
by: John Smith | last post by:
Hi I'm looking for a header-file only STL implementation. I know the vendors provide one with compilers but often they are either buggy or has some other problems. My problem is that under...
385
16876
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
9
4294
by: PengYu.UT | last post by:
Hi, I write the content of a in file "data" (in Sun Machine). Then I read "data" in both SunOS and linux. But the result is different. Do you know how to make it binary data portable. Best...
131
6015
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
11
1965
by: Metaosp | last post by:
Hi, When it comes to code portability, most people would think C is a better choice then C++. That was probably true 5 or 10 years ago, but how about today? Are there still many platforms or...
5
7606
by: Richard Giuly | last post by:
Hello, I would like to write "portable" C++ code that could theoretically run on linux, windows, and other platforms, and I'd like to use VS as the editor/compiler/linker. The simplest thing...
42
3402
by: jacob navia | last post by:
http://slashdot.org/ "The leaner, lighter, faster, and most importantly, BSD Licensed, Compiler PCC has been imported into OpenBSD's CVS and NetBSD's pkgsrc. The compiler is based on the...
69
2567
by: Bill Reid | last post by:
This is how I handle a check that the last character of a text file is a newline: /* checks if newline is last character of text file */ unsigned check_text_file_newline_termination(FILE...
23
3304
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.