[Cython] 'Class' redeclared error if C++ class & file name match those of the wrapper class
nathan12343 at gmail.com
Wed Oct 21 11:52:30 EDT 2015
I'm forwarding this at the request of David Nemesky ("savior" on Freenode),
who I've been chatting with on the cython IRC channel. He was having
trouble signing up to the cython-devel mailing list, so I've gone ahead and
sent his bug report in for him. His report follows below.
Apparently this error happens under very specific circumstances, but I
managed to run into them. When wrapping a C++ class, Cython reports a
"'ClassName' redeclared" error, if:
- the name of the .pyx is the same as the name of the .pxd
- the name of the python class is the same as the name of the C++ class
Mismatch in either the file- or the class name results in a successful
I have modified my fork of the cython-cpp-test repo to make the issue
easily reproducible. In https://github.com/DavidNemeskey/cython-cpp-test/,
try `python setup.py build_ext --inplace` (do not forget to delete all .cpp
and .so files between calls) in the following branches:
- cython_bug (diff file, diff class) -> OK
- diff_file_same_class -> OK
- same_file_diff_class -> OK
- same_file_same_class -> ERROR (https://bpaste.net/show/2c1af5fa5ee2)
Since Cython compiles xxx.pyx to xxx.cpp in this case, in order to avoid
problems with testclass.cpp being overwritten, I implemented the class in
testclass.hpp (in the original repo, there was a .h and a .cpp file).
However, implementing everything in the header is not a pre-requisite of
the bug, as is evident from branch same_file_same_class_diff_c.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cython-devel