[Cython] Multiple modules in one compilation unit

Stefan Behnel stefan_ml at behnel.de
Wed Mar 2 11:48:25 CET 2011

Dag Sverre Seljebotn, 02.03.2011 11:20:
> c) Somehow provide more than one module in the same compilation unit.
> Again, this requires the build to work correctly, but seems less dangerous,
> and also has the advantage of *allowing* static linking of the Fortran
> library, if one wants to.
> But is something like this possible? Could one implement
> cython -o assembly.c file1.pyx file2.pyx file3.pyx
> ...where assembly.so would contain three Python modules? (initfile1,
> initfile2, and so on...)

Can't currently work because the three modules would define the same static 
C names. This could be fixed as part of the PEP 3121 implementation:


Or it could be worked around by overriding the prefixes in Naming.py (which 
sounds ugly).

Generally speaking, I'm -1 on this idea. I don't see a real use case, and 
you're saying yourself that this isn't required to make your Fortran use 
case work either.

> - If you build the Fortran code as a static library (rather common...),
> then each pyx file will have their own copy. This will link successfully
> but likely have a rather poor effect.

So? lxml has two main modules, and if you build it statically against 
libxml2/libxslt, you end up with two static versions of that library in the 
two modules. Takes up some additional space, but otherwise works beautifully.


More information about the cython-devel mailing list