我如何覆盖setup.py默认使用的编译器(gcc)标志? [英] How may I override the compiler (gcc) flags that setup.py uses by default?

查看:1105
本文介绍了我如何覆盖setup.py默认使用的编译器(gcc)标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道setup.py使用与构建python相同的CFLAGS。我有一个我们的C扩展,它是segfaulting。因为 -O2 正在优化某些值,所以我需要构建它 <-c $ c>代码,以便核心文件不足以解决问题。



我只需要修改setup.py,使 -O2 未使用。



我读过distutils文档,特别是 distutils.ccompiler distutils.unixcompiler 并查看如何添加标志和库并包含,但不包括如何修改默认的gcc标志。



<具体来说,这是针对Python 2.5.1上的一个遗留产品,带有一堆backports(Fedora 8,是的,我知道......)。不,我不能改变操作系统或Python版本,我不能,没有大问题,重新编译python。我只需要为其中一个客户的C扩展创建一个,这个客户的环境是唯一的一个分段交易。

解决方案


  • 在运行 setup.py 之前加上 CFLAGS = - O0



     %CFLAGS = -  O0python ./setup.py 

    在编译时, -O0 会附加到 CFLAGS ,因此会覆盖以前的 -O2 设置。

  • 另外一种方法是添加 -O0 extra_compile_args 位于 setup.py

      moduleA = Extension('moduleA',.....,
    include_dirs = ['/ usr / include','/ usr / local /包括'],
    extra_compile_args = [-O0],


  • 如果您想删除所有默认标志,请使用:

     %OPT =python ./setup.py 



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.

I just need to modify setup.py so that -O2 is not used.

I've read distutils documentation, in particular distutils.ccompiler and distutils.unixcompiler and see how to add flags and libs and includes, but not how to modify the default gcc flags.

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.

解决方案

  • Prepend CFLAGS="-O0" before you run setup.py:

    % CFLAGS="-O0" python ./setup.py
    

    The -O0 will be appended to CFLAGS while compiling, therefore will override previous -O2 setting.

  • Another way is add -O0 to extra_compile_args in setup.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆