簡體   English   中英

用C ++無法編譯cython

[英]Cant compile cython with c++

我嘗試在http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html上運行cython示例,我基本上只是將代碼復制到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

我究竟做錯了什么???

Rectangle.h:1:1:錯誤:未知類型名稱'namespace'

namespace僅由C ++編譯器識別。 我猜你打算使用g ++而不是gcc編譯器。 更改build_ext以使用g ++,並且為了清楚起見,將文件重命名為長方體。

在您的setup.py腳本中,將ext_modules中的語言設置為c ++

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

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

Cython現在將調用正確的C ++編譯器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM