在 Cython 中删除编译参数

Remove compile args in Cython

我想用 cython 编译我的 python 项目。 我创建了这个 setup.py 文件:

from setuptools import setup, find_packages
from Cython.Build import cythonize

recursive_tree = [file for file in glob.iglob("sample/**/*.py",  recursive=True)]

setup(
    name                                     = 'sample',
    version                                  = sample.__version__,
    packages                                 = find_packages(),
    author                                   = "42",
    description                              = "Cython Sample",
    include_package_data                     = True,
    ext_modules                              = cythonize(
        recursive_tree,
        nthreads=2,
        exclude="setup.py",
        build_dir = "out",
    ),
)

在这个中,我们可以看到可以添加一些额外的编译参数,但是我们可以做相反的事情并删除一个吗?

当我使用这个命令时: python setup.py build_ext --inplace 我得到了这个 gcc 配置:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python3.6m -c out/sample/hello.c -o build/temp.linux-x86_64-3.6/out/sample/hello.o

gcc -pthread -shared build/temp.linux-x86_64-3.6/out/sample/hello.o -o build/lib.linux-x86_64-3.6/hello.cpython-36m-x86_64-linux-gnu.so

如何删除 -g 选项?

参考类似的问题:How may I override the compiler (gcc) flags that setup.py uses by default?(我不认为它 完全 是重复的)。他们通过添加额外的命令行参数来撤消 setup.py 默认添加的参数来解决类似的问题。

在这种情况下 -g0 "negates -g"。因此将 -g0 添加到 extra_compile_args

setup(... # everything as before
      extra_compile_args = ['-g0'])