setup.py for a Cython module calling external C code with its .pxd wrapper

62 views
Skip to first unread message

bibi21000

unread,
Oct 2, 2012, 6:32:43 AM10/2/12
to cython...@googlegroups.com
hi ghis
don't if it can help you but I've a setup.py for python-openzwave :
http://code.google.com/p/python-openzwave/source/browse/

the lib (pyx) is in lib and the pure python code (api) in src

but ...
this works fine on most of computers
but doesn't on some : the setup.py doesn't call cython to create the cpp source file
don't know why
hope this helps

bibi21000

bibi21000

unread,
Oct 2, 2012, 4:45:00 PM10/2/12
to cython...@googlegroups.com


Le mardi 2 octobre 2012 18:00:59 UTC+2, Ghis a écrit :
Hi bibi21000,

I have had a look at your setup.py. Please correct me if I am wrong but, in your case your C++ library (libopenzwave) is already installed system-wide and you provide the relevant wrappers (.pyx) and path to the static library in the build process within your setup.py. 
Yes and No :
When compiling for debian, the libopenzwave needs to be installed and is dinamically linked to the pyx part
But when compiling for linux, the library is linked statically

In my case, the library (libcstat) is not compiled, neither statically or dynamically. I have a folder with the sources and headers + a pxd with some wrapper code which I want to import later on in other modules, like the printfff one. Since, the library is not installed, I guess it has to be part of the build process in the setup.py.
What kind of linking do you want ? static or dynamic ?
If you want to link it dynamically, you must build and install the c part before compiling the pyx (as far as I know)
But if you want to link it statically, I think this doc can help you : http://docs.python.org/extending/building.html



Thanks for this first piece of advice, other suggestions ?

Ghis
Hth

Chris Barker

unread,
Oct 2, 2012, 6:56:37 PM10/2/12
to cython...@googlegroups.com
On Tue, Oct 2, 2012 at 9:00 AM, Ghis <ghis...@gmail.com> wrote:
> I have had a look at your setup.py. Please correct me if I am wrong but, in
> your case your C++ library (libopenzwave) is already installed system-wide
> and you provide the relevant wrappers (.pyx) and path to the static library
> in the build process within your setup.py.
>
> In my case, the library (libcstat) is not compiled, neither statically or
> dynamically. I have a folder with the sources and headers + a pxd with some
> wrapper code which I want to import later on in other modules, like the
> printfff one. Since, the library is not installed, I guess it has to be part
> of the build process in the setup.py.

well, as suggested, you could built it ahead of time as a libarry, but
you can also simply list all the libcstat files as source files in
your Extension() call. Then distutils will build the whole pile
together.

If you are calling it all from a single pyx module, that is easy and works fine.

If you have multiple pxy modules that need to access the lib, then you
do want to built it separately, but depending on what OS's you want to
run on, that can be pretty easy.

-Chris




>
> Thanks for this first piece of advice, other suggestions ?
>
> Ghis
>
>
> Le mardi 2 octobre 2012 11:32:43 UTC+1, bibi21000 a écrit :
>>
--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov
Reply all
Reply to author
Forward
0 new messages