Cc1Puls:警告:命令行选项“Wstrict原型”对于艾达/C/Objc有效,但对于C++无效

2024-04-26 06:29:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建一个用于Python的C++扩展。我看到在编译过程中生成此警告-当类型:

python setup.py build_ext -i

是什么引起的,我该怎么解决?

顺便说一下,这是我的安装文件的副本:

#!/usr/bin/env python

    """
    setup.py file for SWIG example
    """

    from distutils.core import setup, Extension


    example_module = Extension('_foolib',
                               sources=['example_wrap.cxx', 
                                        '../wrapper++/src/Foo.cpp'
                                       ],
                               libraries=["foopp"]
                               )

    setup (name = 'foolib',
           version = '0.1',
           author      = "Me, Myself and I",
           description = """Example""",
           ext_modules = [example_module],
           py_modules = ["example"],
           )

我在Ubuntu上使用gcc 4.4.3


Tags: pybuildmodules警告类型bin过程example
2条回答

从OPT环境变量中删除-Wstrict原型没有任何效果。有效的方法是将build_ext子类划分如下:

from distutils.command.build_ext import build_ext
from distutils.sysconfig import customize_compiler

class my_build_ext(build_ext):
    def build_extensions(self):
        customize_compiler(self.compiler)
        try:
            self.compiler.compiler_so.remove("-Wstrict-prototypes")
        except (AttributeError, ValueError):
            pass
        build_ext.build_extensions(self)

然后在setup函数中使用my_build_ext

setup(cmdclass = {'build_ext': my_build_ext})

-Wstrict-prototypes选项由distutils作为OPT变量的一部分从/usr/lib/pythonX.Y/config/Makefile读取。它看起来有些老套,但是您可以通过在setup.py中设置os.environ['OPT']来覆盖它。

下面是一个似乎不太有害的代码:

import os
from distutils.sysconfig import get_config_vars

(opt,) = get_config_vars('OPT')
os.environ['OPT'] = " ".join(
    flag for flag in opt.split() if flag != '-Wstrict-prototypes'
)

相关问题 更多 >