I am trying the Cython tutorial which uses a C++ vector (https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html). It compiles fine, but when I import the module I receive Symbol not found: __ZTINSt8ios_base7failureB5cxx11E
# distutils: language=c++
from libcpp.vector cimport vector
def primes(unsigned int nb_primes):
cdef int n, i
cdef vector[int] p
p.reserve(nb_primes) # allocate memory for 'nb_primes' elements.
n = 2
while p.size() < nb_primes: # size() for vectors is similar to len()
for i in p:
if n % i == 0:
break
else:
p.push_back(n) # push_back is similar to append()
n += 1
# Vectors are automatically converted to Python
# lists when converted to Python objects.
return p
My setup.py:
from setuptools import setup, Extension
from Cython.Build import cythonize
import os
os.environ["CC"] = "gcc-10"
os.environ["CXX"] = "gcc-10"
ext_modules = [
Extension(
"test",
["test.pyx"],
language = "c++"
)
]
setup(
ext_modules = cythonize(ext_modules, annotate=True),
)
What have I done wrong?
Edit: By removing the os.environ settings and setting language level to 3 (instead of the default, 2 ?!!) I was able to fix this. Thanks to everyone who helped.