Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython not recognizing c++11 commands

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?

like image 765
The Dude Avatar asked Dec 04 '14 22:12

The Dude


1 Answers

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))
like image 68
Messa Avatar answered Sep 24 '22 06:09

Messa