Cython -std = c ++ 11错误,同时使用C和C ++

rp

我是Cython的新手,我正在尝试从该项目编译Cython,没有成功。

有了这个setup.py,

from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension

sources_list = ["timgraph.pyx", "Graph.cpp", "InfGraph.cpp", "sfmt/SFMT.c"]

setup(ext_modules=[Extension("pytim",
                             sources=sources_list,
                             language="c++",
                             extra_compile_args=["-std=c++11"])
                  ],
      cmdclass={'build_ext':build_ext})

我运行以下命令:

python setup.py build_ext --inplace

并得到以下错误:

error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
error: command 'clang' failed with exit status 1

我正在运行macOS High Sierra 10.13.2,Python 3.6.2,Cython 0.27.3和Apple LLVM版本9.0.0,以防任何帮助。

编辑:我认为可能是因为尝试同时编译C和C ++,因为我可以为C ++运行Cython示例,并且效果很好。但是我不知道如何解决extra_compile_args适用于所有源的事实,包括“ sfmt / SFMT.c”。

rp

仅作记录,解决方案非常简单:extra_compile_args完全删除参数,但仍将语言参数设置为c++,即

from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension

sources_list = ["timgraph.pyx", "Graph.cpp", "InfGraph.cpp", "sfmt/SFMT.c"]

setup(ext_modules=[Extension("pytim",
                         sources=sources_list,
                         language="c++")
                   ],
      cmdclass={'build_ext':build_ext})

无论出于何种原因,这都能成功编译C和C ++。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章