Problem including std :: vector in cython

I have a problem importing a vector class in cython using

from libcpp.vector cimport vector 

when I add this and try to compile a pyx file, I get

 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 

Here is my 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, ) 

Greetings

+7
source share
1 answer

Since std::vector is C ++ code, you need to install the correct language:

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

Then, g++ should be used instead of gcc , and the file name should end in .cpp or .cc . See this answer for more details.

+10
source

All Articles