Having trouble with file hierarchy/cimports

45 views
Skip to first unread message

nickt...@gmail.com

unread,
Aug 11, 2016, 12:31:08 PM8/11/16
to cython-users
Hello,

I have always been having some trouble with correctly cimporting in cython, but always managed to somehow get my bindings to compile. Now I completely broke it and cannot understand why.

I'm getting weird error messages like,

Error compiling Cython file:
------------------------------------------------------------
...
cimport mch
from libcpp.vector cimport vector

cdef
class Configuration:
    cdef mch
.Configuration* thisptr
    cdef vector
[mch.shape.Variant]* shapes_ptr
                               
^
------------------------------------------------------------

pymch
/Configuration.pxd:6:33: unknown type in template argument

The module cython is complaining about is correctly imported in the corresponding __init__.pxd files.

You can find the code for the bindings here. I've tried with both Cython 0.22 and 0.24.

If you need more information, please tell.

Robert Bradshaw

unread,
Aug 11, 2016, 1:29:05 PM8/11/16
to cython...@googlegroups.com
Your "here" link is broken. Could you whittle this down to a minimal
reproducible example?
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cython-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

nickt...@gmail.com

unread,
Aug 11, 2016, 6:24:29 PM8/11/16
to cython-users
I wish I could, it would make spotting the problem much easier. I will try going back to my previous commit and try to isolate the problem by applying more incremental changes.

In the meantime, here is another try to link the code,

nickt...@gmail.com

unread,
Aug 12, 2016, 5:04:10 AM8/12/16
to cython-users
I was able to pinpoint the problem, although I do not understand what causes it.

I have a file hierarchy like this,

toplevel
|-- setup.py

|-- ...

`-- pymch/
    |-- __init__.py

    |-- __init__.pxd

    |-- ...
(.pxd and .pyx files for interfacing with python)
    `
-- mch/ (.pxd files for binding the C++ code)
        |-- __init__.pxd

        |-- ...

        `-- shape/

            |-- __init__.pxd

            |-- convex.pxd

            |-- convex_shape_definition.pxd

            `-- ...


Here is how `convex_shape_definition.pxd` looks like,

cimport pymch.mch.clam as clam

cdef
extern from "MCH/shape/convex_shape_definition.h" namespace "MCH::shape":
    cdef cppclass
Convex
    cdef cppclass
ConvexShapeDefinition:
       
ConvexShapeDefinition()
       
ConvexShapeDefinition(const ConvexShapeDefinition&)
        clam
.Vec3[double] pos_;
        clam
.Quat[double] rot_;
       
double size_;
       
const Convex* shape_;


If I don't cimport convex_shape_definition in convex.pxd, then I don't get any errors. Also, if I don't cimport clam above (and comment out the pos_, and rot_ declarations), but do cimport convex_shape_definition in convex.pxd, I also don't get any errors.

Here are the imports of convex.pxd,

from pymch.mch.shape.convex_shape_definition cimport ConvexShapeDefinition
from pymch.mch.clam.Vec3 cimport Vec3
from libcpp.vector cimport vector

I hope this helps solve the problem.

nickt...@gmail.com

unread,
Aug 13, 2016, 5:28:52 AM8/13/16
to cython-users
I seem to have solved the problem. The problem probably stemmed from importing parent modules from within submodules. I have now converted all imports to being relative, which allowed it to compile.
Reply all
Reply to author
Forward
0 new messages