Windows 10, Python 3.8.3, Cython 3.0a5, Visual Studio 2017 version 15.9.20.
Let's consider the following example:
a.h:
#pragma once
#include <memory>
std::unique_ptr<int> f() {
return std::make_unique<int>(123456);
}
b.pyx:
from libcpp.memory cimport unique_ptr
cdef extern from "a.h":
unique_ptr[int] f() except +
def g():
cdef unique_ptr[int] p = f()
setup.py:
from setuptools import setup, Extension
from Cython.Build import cythonize
extensions = [Extension(
"b",
["b.pyx"],
language='c++'
)]
setup(ext_modules=cythonize(extensions, compiler_directives={"language_level" : "3"}))
Expected behavior
python setup.py build builds a .pyd-file.
Observed behavior
python setup.py build produces a message referencing error C2280, doesn't build a .pyd-file.
Workaround
Adding extra_compile_args=["/Zc:__cplusplus"] to the arguments of Extension fixes the problem.
Likely reason
MSVC defines __cplusplus as 199711L by default (details)
Cython defines __PYX_STD_MOVE_IF_SUPPORTED like this:
(source)
#if __cplusplus >= 201103L
#include <utility>
#define __PYX_STD_MOVE_IF_SUPPORTED(x) std::move(x)
#else
#define __PYX_STD_MOVE_IF_SUPPORTED(x) x
#endif
The generated .cpp file tries to copy a unique_ptr, and thus doesn't compile.
Windows 10, Python 3.8.3, Cython 3.0a5, Visual Studio 2017 version 15.9.20.
Let's consider the following example:
a.h:
b.pyx:
setup.py:
Expected behavior
python setup.py buildbuilds a.pyd-file.Observed behavior
python setup.py buildproduces a message referencing error C2280, doesn't build a.pyd-file.Workaround
Adding
extra_compile_args=["/Zc:__cplusplus"]to the arguments ofExtensionfixes the problem.Likely reason
MSVC defines
__cplusplusas199711Lby default (details)Cython defines
__PYX_STD_MOVE_IF_SUPPORTEDlike this:(source)
The generated
.cppfile tries to copy aunique_ptr, and thus doesn't compile.