[Pyrex] sharing funcitons with distutils for .pyx

Jim Kleckner jek-gmane at kleckner.net
Thu Sep 20 17:45:35 CEST 2007


Thank you for your pointers, Stefan.

Stefan Behnel wrote:
> Jim Kleckner wrote:
...
>> I have a .pyx file that depends on functions defined in a .c
>> file that is included with another .pyx, say it is "cfunc1" defined in 
>> cfuncs.c
...
>> If I don't include "libraries=['mod1',]" then I get an undefined 
>> reference to cfunc1 when linking mod2.dll.
> 
> You could use "cfuncs.c" as source file for both modules.

I ended up doing this for now, with the result that
there are two copies of the same library, one in
each pyx->dll.

I suppose that I could surrender and rename
cfuncs.c to be libcfuncs.c, create a dll
named libcfuncs.dll and have it work with
the "libraries=['cfuncs']" notation by
referencing it in both pyx extension lines.
There isn't any initialization code which
I suspect is where most of the other complexity
of solutions arises.

...
> Here is an example of an implementation of such functions (basically wrappers
> in this case):
> 
> http://codespeak.net/svn/lxml/trunk/src/lxml/public-api.pxi
> 
> Here is their .pxd declaration:
> 
> http://codespeak.net/svn/lxml/trunk/src/lxml/etreepublic.pxd

This is an excellent example, thanks.

Since I control the libaries in question in this case,
I can just do what Greg suggests in the next post
and wrap it in a more "Pythonic" fashion.
That would be the next step probably rather than
creating libcfuncs.c.

Thanks again - Jim




More information about the Pyrex mailing list