在ipython中用Cython包装C ++标准库 [英] Wrapping C++ Standard library with Cython in ipython

查看:105
本文介绍了在ipython中用Cython包装C ++标准库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Cython文档,我编写以下cython代码,如下所示:

According to the Cython documentation ,I write the following cython code as follows:

In [1]:%load_ext Cython
In [2]: %%cython
         from libcpp.vector cimport vector
​         cdef vector[int] *vec_int = new vector[int](10)

编译后,ipython产生以下错误:

After compiling,the ipython generated the following error:

Error compiling Cython file:
------------------------------------------------------------ 
... 
from libcpp.vector cimport vector 
cdef vector[int] *vec_int = new vector[int](10) 
                               ^ 
------------------------------------------------------------
/Users/m/.ipython/cython/_cython_magic_a72abb419ccf1b31db9a1851b522a4bf.pyx:3:32: Operation only allowed in c++

我的代码有什么问题?

推荐答案

您需要告诉 cython 您正在编译 C ++ 而不是 C ,通过特殊注释

You need to tell cython that you are compiling C++ and not C, through the special comment

# distutils: language = c++

将此添加到 %% cython 之后块将解决您的问题。

adding this after the %%cython block will fix your problem.

这篇关于在ipython中用Cython包装C ++标准库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆