我看过this question和Using C++ in Cython,但是没有成功编译我的代码。我的理解是,包括language="c++"
可以解决问题,但事实并非如此。
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)
)
运行python setup.py build_ext -i
会产生:
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