我正在研究一个从Python调用C ++的项目。为此,我们使用Cython。使用命令“ python3.6 setup.py build_ext --inplace”进行编译时,将使用编译器“ x86_64-linux-gnu-gcc”。是否可以使用“ arm-linux-gnueabihf-g ++”之类的其他编译器?
还可以添加诸如“ -DPLATFORM = linux”之类的编译选项吗?
这是setup.py:
from distutils.core import setup, Extension
from Cython.Build import cythonize
setup(ext_modules = cythonize(Extension(
"app",
sources=["app.pyx", "myapp.cpp"],
language="c++",
include_dirs=["../base"]
)))
Distutils默认情况下使用CC
系统环境变量来决定要使用的编译器。您可以运行python脚本,以便在调用CC
之前在脚本的开头将setup()
变量设置为所需的值。
关于将标志传递给编译器,请在extra_compile_args
模块中添加一个Extension()
命名参数。例如,可能看起来像这样:
from distutils.core import setup, Extension
from Cython.Build import cythonize
setup(ext_modules = cythonize(Extension(
"app",
sources=["app.pyx", "myapp.cpp"],
language="c++",
include_dirs=["../base"],
extra_compile_args=["-DPLATFORM=linux"]
)))