无法使用c ++编译cython

时间:2013-09-13 19:18:38

标签: c++ python compiler-construction cython

我尝试运行cython示例 http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html 我基本上只是复制了Rectangle.h,Rectangle.cpp,setup.py和rect.pyx中的代码 但是,当我跑 python setup.py build_ext --inplace 我收到了错误

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

我做错了什么???

2 个答案:

答案 0 :(得分:2)

Rectangle.h:1:1:错误:未知类型名称'命名空间'

namespace只能被C ++编译器识别。我猜你的意思是使用g ++而不是gcc编译器。将build_ext更改为使用g ++,并且为了清楚起见,将文件重命名为rectangle.cpp

答案 1 :(得分:1)

在setup.py脚本中,将语言设置为ext_modules中的c ++

...
ext_modules=[
    Extension("rect",
    sources=["rect.pyx"],
    language="c++",
    )]

setup(
  name = 'rect',
  ext_modules = cythonize(ext_modules),
)

Cython现在将调用正确的c ++编译器

相关问题