cimport results in struct declaration being copied into another location

18 views
Skip to first unread message

Colin Pattison

unread,
Jun 14, 2016, 1:14:55 AM6/14/16
to cython-users

Hey Guys - 


I’ve just started using Cython after having handwritten extensions for a while. I’ve run into an issue and would appreciate any insight you guys have - I have a common pxd which wraps our standard data representation. I then have module B built separately that cimports the data representation. This then results in a redefinition error as the struct DataPy appears in the header for the common module and then is redefined in the cpp of module B. Is there any way around this?


A replication of this is attached - build the common module first using the setup.sh, then build the session module using the setup.sh. DataPy will be declared in common.h and then redeclared in session.cpp.


Is there any way to avoid this happening?


Cheers

C

redef.tgz

Robert Bradshaw

unread,
Jun 14, 2016, 1:49:54 PM6/14/16
to cython...@googlegroups.com
The problem is that you're using "include."

Just define your Data class in common.pxd/common.pyx, and cimport them
from everywhere else.
> --
>
> ---
> 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.

Colin Pattison

unread,
Jun 15, 2016, 4:01:01 PM6/15/16
to cython-users
Thanks Rob - the problem is I needed to get access to the function from a pure C++ class to convert the C++ data representation into a Python one. 

I got around the issue by returning a PyObject* rather than my extension type which meant it wasn't duplicated into the header. At this point however I was not correctly using the "public api" declaration, I suspect if I had declared the function properly as an api one and included the _api.h file this would have been fine

C
Reply all
Reply to author
Forward
0 new messages