如何覆盖 setup.py 默认使用的编译器 (GCC) 标志? [英] How may I override the compiler (GCC) flags that setup.py uses by default?
问题描述
我知道 setup.py
使用与构建 Python 相同的 CFLAGS
.我有一个我们的 C 扩展,它是段错误的.我需要在 没有 -O2
的情况下构建它,因为 -O2
正在优化一些值和代码,因此核心文件不足以确定问题.
I understand that setup.py
uses the same CFLAGS
that were used to build Python. I have a single C extension of ours that is segfaulting. I need to build it without -O2
because -O2
is optimizing out some values and code so that the core files are not sufficient to pin down the problem.
我只需要修改setup.py
以便不使用-O2
.
I just need to modify setup.py
so that -O2
is not used.
我已经阅读了 distutils
文档,特别是 distutils.ccompiler
和 distutils.unixccompiler
并了解如何添加标志和库以及包含,但不知道如何修改默认的 GCC 标志.
I've read distutils
documentation, in particular distutils.ccompiler
and distutils.unixccompiler
and see how to add flags and libs and includes, but not how to modify the default GCC flags.
具体来说,这是针对 Python 2.5.1 上的遗留产品,带有一堆向后移植(Fedora 8,是的,我知道...).不,我不能更改操作系统或 Python 版本,而且我不能毫无问题地重新编译 Python.我只需要为一个客户构建一个单独的 C 扩展,其环境是唯一的一个段错误.
Specifically, this is for a legacy product on Python 2.5.1 with a bunch of backports (Fedora 8, yes, I know...). No, I cannot change the OS or Python version and I cannot, without great problems, recompile Python. I just need to build a one off of the C extension for one customer whose environment is the only one segfaulting.
推荐答案
在运行
setup.py
之前添加CFLAGS="-O0"
:% CFLAGS="-O0" python ./setup.py
-O0
将在编译时附加到CFLAGS
,因此将覆盖之前的-O2
设置.The
-O0
will be appended toCFLAGS
while compiling, therefore will override previous-O2
setting.另一种方法是将
-O0
添加到setup.py
中的extra_compile_args
:Another way is add
-O0
toextra_compile_args
insetup.py
:moduleA = Extension('moduleA', ....., include_dirs = ['/usr/include', '/usr/local/include'], extra_compile_args = ["-O0"], )
如果要删除所有默认标志,请使用:
If you want to remove all default flags, use:
% OPT="" python ./setup.py
这篇关于如何覆盖 setup.py 默认使用的编译器 (GCC) 标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!