Search code examples
pythonc++cython

Cant compile cython with c++


I tried to run the cython example on http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html I basically just copied the code in Rectangle.h, Rectangle.cpp, setup.py and rect.pyx However, when I run python setup.py build_ext --inplace I get the error

running build_ext
building 'rect' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c rect.c -o build/temp.linux-x86_64-2.7/rect.o
In file included from rect.c:235:0:
Rectangle.h:1:1: error: unknown type name ‘namespace’
Rectangle.h:1:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
rect.c:236:15: fatal error: ios: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

What am I doing wrong???


Solution

  • Rectangle.h:1:1: error: unknown type name ‘namespace’

    namespace is only recognized by C++ compilers. I'm guessing you meant to use g++ instead of the gcc compiler. Change your build_ext to use g++ and also for the sake of clarity, rename your file to rectangle.cpp