首页 > 解决方案 > 如何包装 C++Cython 的图书馆?

问题描述

我有一些来自同事的代码,cython.weave用于包装 C++ 库中的函数:

def partialsort(a, K):
    support_code = "#include <algorithm>"
    code = "std::partial_sort (&ak(0), &ak(K), &ak(N));"
    N = len(a)
    ak = a.copy()
    vars = ['ak', 'K', 'N']
    s = weave.inline(code, vars, support_code=support_code,
                     type_converters=converters.blitz)

随着 Weave 工具的消失,如果可能的话,我想用 Cython 替换它。到目前为止,我已经根据http://docs.cython.org/en/latest/src/userguide/external_C_code.html尝试了我的运气,并在 Cython 模块中尝试了以下操作,只是为了检查我是否可以访问该库:

cdef extern from "<algorithm>":
    pass

当我尝试构建 Cython 模块时,出现以下错误:

csorting.c:604:10: fatal error: algorithm: No such file or `folder
 #include <algorithm>
          ^~~~~~~~~~~
compilation terminated.

据我了解,<algorithm>是一个 C++ 库。C++ 是这里的问题吗?我有g++,但 Cython 构建设置使用gcc. 是<algorithm>一个必须单独安装的库吗?

标签: c++cythonize

解决方案


推荐阅读