1

I have looked at this question and Using C++ in Cython but have had no success in getting my code to compile. My understanding was that including language="c++" would do the trick, but this does not seem to be the case.

cytest.pyx

from libcpp.unordered_map cimport unordered_map

cdef unordered_map[int, int] umap

setup.py

from distutils.core import setup, Extension
from Cython.Build import cythonize

ext = Extension(
    "cytest",
    sources=["cytest.pyx"],
    language="c++"
)
setup(
    name="cytest",
    ext_modules=cythonize(ext)
)

Running python setup.py build_ext -i yields:

Compiling cytest.pyx because it changed.
[1/1] Cythonizing cytest.pyx
/home/miniconda3/envs/cyenv/lib/python3.7/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/CyTest/cytest.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'cytest' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/miniconda3/envs/cyenv/include -arch x86_64 -I/home/miniconda3/envs/cyenv/include -arch x86_64 -I/home/miniconda3/envs/cyenv/include/python3.7m -c cytest.cpp -o build/temp.macosx-10.7-x86_64-3.7/cytest.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead
      [-Wstdlibcxx-not-found]
cytest.cpp:624:10: fatal error: 'ios' file not found
#include "ios"
         ^~~~~
1 warning and 1 error generated.
error: command 'gcc' failed with exit status 1
Matt Eding
  • 917
  • 1
  • 8
  • 15

0 Answers0