Hello community,
I have encountered another problem wrapping a C++ library with Cython 0.24.2.
The Library consists of various classes which I want to wrap with Cython. Therefore I wanted to put each class into one pyx file such that I have a structure of:
ClassA.pyx cppClassA.pxd
ClassB.pyx cppClassB.pxd
...
With the pyx file containing the Wrapper class and the pxd file containing the C++ interface. Those Classes also use each other to wrap method returns.
All of those Classes should be compiled to one .so file such that I have a module that wraps the library. I have created a MyLibrary.pyx that includes all of my ClassX.pyx files. My setup.py creates an Extension with MyLibrary.pyx and might also list all of my ClassX.pyx files as source. It does not seem to matter, as both possibilities produce an MyLibrary.so, but if I try to import MyLibrary in python or sage, it throws an error that "No Module named cppClassA". My setup.py links with all required dependencies.
After looking at the generated code the error message points to: in the produced MyLibrary.cpp, it fails where:
/*--- Type import code ---*/
__pyx_ptype_17cppClassA_ClassA = __Pyx_ImportType("cppClassA", "ClassA", sizeof(struct __pyx_obj_17cppClassA_ClassA), 1); if (unlikely(!__pyx_ptype_17cppClassA_ClassA)) __PYX_ERR(5, 18, __pyx_L1_error)
It fails with the first class that is imported in the "Type import code" section of the generated Code.
Right now all of my files are placed in the same directory. (ClassX.pyx, cppClassX.pxd, MyLibrary.py, setup.py)
What am I doing wrong? Do I need to structure my code differently (I have read about using pxi files), are there more/other possibilities with a newer Cython version? Do I need an explicit __init__.py file and if I do, what does it contain? I have been searching Mailing lists and websites but I cannot seem to find a common opinion on how to do this properly.