I'm wrapping a C++ class with Python, and I cannot compile any C++11 features with the Cython module.
Everything compiles okay when compiling the C++ alone. But when I run this setup.py below:
setup(
    ext_modules = cythonize(
       "marketdata.pyx",            # our Cython source
       sources=["cpp/OBwrapper.cpp, cpp/OrderBook/orderbook.h, cpp/OrderBook/orderbook.cpp"],  # additional source file(s)
       language="c++",             # generate C++ code
       extra_compile_args=["-std=c++11"]
    ))
In my .pyx file header:
# distutils: language = c++
# distutils: sources = cpp/OBwrapper.cpp cpp/OrderBook/orderbook.cpp
I get a ton of errors that have to do with them not recognizing c++11 commands, like 'auto'.
For example:
cpp/OrderBook/orderbook.cpp(168) : error C2065: 'nullptr' : undeclared identifier
How can I get this to work?
Try using Extension: setup(ext_modules=cythonize([Extension(...)], ...).
This setup.py works for me (on Debian Linux):
from setuptools import setup, find_packages, Extension
from Cython.Build import cythonize
from glob import glob
extensions = [
    Extension(
        'my_proj.cython.hello',
        glob('my_proj/cython/*.pyx')
        + glob('my_proj/cython/*.cxx'),
        extra_compile_args=["-std=c++14"])
]
setup(
    name='my-proj',
    packages=find_packages(exclude=['doc', 'tests']),
    ext_modules=cythonize(extensions))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With