extra_compile_args in Cython

前端 未结 2 1481
逝去的感伤
逝去的感伤 2020-12-31 01:15

I want to pass some extra options to the Cython compiler by using extra_compile_args.

My setup.py:

from distut         


        
相关标签:
2条回答
  • 2020-12-31 01:34

    Mike Muller's answer works, but builds extensions in the current directory, not next to the .pyx file when --inplace is given as in:

    python3 setup.py build_ext --inplace
    

    So my workaround is to compose a CFLAGS string and override the env variable:

    os.environ['CFLAGS'] = '-O3 -Wall -std=c++11 -I"some/custom/paths"'
    setup(ext_modules = cythonize(src_list_pyx, language = 'c++'))
    
    0 讨论(0)
  • 2020-12-31 01:41

    Use the more traditional way without cythonize to supply extra compiler options:

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    
    setup(
      name = 'Test app',
      ext_modules=[
        Extension('test',
                  sources=['test.pyx'],
                  extra_compile_args=['-O3'],
                  language='c++')
        ],
      cmdclass = {'build_ext': build_ext}
    )
    
    0 讨论(0)
提交回复
热议问题