gpt4 book ai didi

vector - 问题包括 std::vector 到 cython

转载 作者:行者123 更新时间:2023-12-02 03:07:56 24 4
gpt4 key购买 nike

我在使用将向量类导入 cython 时遇到问题

from libcpp.vector cimport vector

当我添加这个并尝试编译我得到的 pyx 文件时

python setup.py build_ext --inplace
running build_ext
skipping 'kmc_cy.c' Cython extension (up-to-date)
building 'kmc_cy' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -fPIC -I/usr/include/python2.7 -c kmc_cy.c -o build/temp.linux-x86_64-2.7/kmc_cy.o
kmc_cy.c:254:18: fatal error: vector: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

这是我的 setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import sys
sys.path.append("/usr/lib64/python2.7/site-packages/Cython/Includes/libcpp")

ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"])]

setup(
name = 'kmc_cy',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
)

干杯

最佳答案

由于std::vector是C++代码,因此需要设置正确的语言:

  ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"],language='c++')]

那么应使用 g++ 而不是 gcc,并且文件名应以 .cpp.cc 结尾>。请参阅this answer更多细节。

关于vector - 问题包括 std::vector 到 cython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13802050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com